使用 fastcgi 在共享主机上设置的 Pyramid 将 .fcgi 文件返回给浏览器
Pyramid set up on a shared host with fastcgi gives the .fcgi file back to the browser
任何人都可以帮助我在带有金字塔的共享主机上设置生产服务器的过程吗?我搜索了一整天试图使这项工作有效,但没有任何效果。
我在编写 .htaccess 和 index.fcgi 文件时遇到问题。我试图结合这些教程; 1, 2, 3, 4 弄明白了,但是当我访问该网站时,我看到的是 index.fcgi 的内容,而不是应用程序。我已经完成了这些步骤;
在主目录中为python创建了一个虚拟环境并激活了它:
mkdir temp; cd temp
curl -O https://pypi.python.org/packages/source/v/virtualenv/virtualenv-12.0.7.tar.gz
gzip -cd virtualenv-12.0.7.tar.gz |tar xf -
cd virtualenv-12.0.7
python2.7 setup.py install --user
cd ~
~/.local/bin/virtualenv pyramid --python=python2.7
source ~/pyramid/bin/activate
在虚拟环境中安装金字塔。
pip install pyramid
创建了一个测试项目;
pcreate -s starter myProject
cd myProject
python setup.py install
已安装 flup
pip install flup
在我的 public_html 文件夹中创建了一个 index.fcgi 文件,内容如下:
#!/home3/reyhane/pyramid/bin/python
import os
import sys
myapp = '/home3/reyhane/myProject'
inifile = 'production.ini'
sys.path.insert(0, myapp )
from paste.deploy import loadapp
wsgi_app = loadapp('config:' + myapp + '/' + inifile)
if __name__ == '__main__':
from flup.server.fcgi import WSGIServer
WSGIServer(wsgi_app).run()
使 index.fcgi 可执行;
cd public_html
chmod +x index.fcgi
它的权限是0755.
已将 public_html 文件夹中的 .htaccess 文件修改为:
AddHandler fastcgi-script .fcgi
DirectoryIndex index.fcgi
RewriteEngine On
RewriteBase /
RewriteRule ^index\.fcgi$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.fcgi/ [L]
AddType "text/html; charset=UTF-8" html
AddType "text/plain; charset=UTF-8" txt
AddCharset UTF-8 .html
AddDefaultCharset UTF-8
所以我的目录如下所示:
home3/reyhane/
|-- pyramid
|-- myProject
| |-- myProject
| |-- production.ini
|-- public_html/
| |-- index.fcgi
| |-- .htaccess
似乎 .htaccess 文件正在执行它的工作,因为页面被重定向到 index.fcgi,但 index.fcgi 肯定有问题。
我有以下 htaccess 文件工作正常:
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ YOUR_APP_NAME.fcgi/ [QSA,L]
和 FCGI 文件:
#$HOME/YOUR_APP_NAME/bin/python
import sys
from paste.deploy
import loadapp
from flup.server.fcgi_fork import WSGIServer
app = loadapp('config:$HOME/YOUR_APP_NAME/src/production.ini')
server = WSGIServer(app)
server.run()
我在文章 'Run Pyramid on Shared Hosting' 中描述了这种情况下的 Pyramid 部署。希望对你有用。
任何人都可以帮助我在带有金字塔的共享主机上设置生产服务器的过程吗?我搜索了一整天试图使这项工作有效,但没有任何效果。
我在编写 .htaccess 和 index.fcgi 文件时遇到问题。我试图结合这些教程; 1, 2, 3, 4 弄明白了,但是当我访问该网站时,我看到的是 index.fcgi 的内容,而不是应用程序。我已经完成了这些步骤;
在主目录中为python创建了一个虚拟环境并激活了它:
mkdir temp; cd temp curl -O https://pypi.python.org/packages/source/v/virtualenv/virtualenv-12.0.7.tar.gz gzip -cd virtualenv-12.0.7.tar.gz |tar xf - cd virtualenv-12.0.7 python2.7 setup.py install --user cd ~ ~/.local/bin/virtualenv pyramid --python=python2.7 source ~/pyramid/bin/activate
在虚拟环境中安装金字塔。
pip install pyramid
创建了一个测试项目;
pcreate -s starter myProject cd myProject python setup.py install
已安装 flup
pip install flup
在我的 public_html 文件夹中创建了一个 index.fcgi 文件,内容如下:
#!/home3/reyhane/pyramid/bin/python import os import sys myapp = '/home3/reyhane/myProject' inifile = 'production.ini' sys.path.insert(0, myapp ) from paste.deploy import loadapp wsgi_app = loadapp('config:' + myapp + '/' + inifile) if __name__ == '__main__': from flup.server.fcgi import WSGIServer WSGIServer(wsgi_app).run()
使 index.fcgi 可执行;
cd public_html chmod +x index.fcgi
它的权限是0755.
已将 public_html 文件夹中的 .htaccess 文件修改为:
AddHandler fastcgi-script .fcgi DirectoryIndex index.fcgi RewriteEngine On RewriteBase / RewriteRule ^index\.fcgi$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.fcgi/ [L] AddType "text/html; charset=UTF-8" html AddType "text/plain; charset=UTF-8" txt AddCharset UTF-8 .html AddDefaultCharset UTF-8
所以我的目录如下所示:
home3/reyhane/
|-- pyramid
|-- myProject
| |-- myProject
| |-- production.ini
|-- public_html/
| |-- index.fcgi
| |-- .htaccess
似乎 .htaccess 文件正在执行它的工作,因为页面被重定向到 index.fcgi,但 index.fcgi 肯定有问题。
我有以下 htaccess 文件工作正常:
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ YOUR_APP_NAME.fcgi/ [QSA,L]
和 FCGI 文件:
#$HOME/YOUR_APP_NAME/bin/python
import sys
from paste.deploy
import loadapp
from flup.server.fcgi_fork import WSGIServer
app = loadapp('config:$HOME/YOUR_APP_NAME/src/production.ini')
server = WSGIServer(app)
server.run()
我在文章 'Run Pyramid on Shared Hosting' 中描述了这种情况下的 Pyramid 部署。希望对你有用。