任何人都可以帮我解决在金字塔共享主机上设置生产服务器的过程吗?我搜索了整整一天试图做这项工作,但没有任何作用.
我在编写.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
>安装了痘痘
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/$1 [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/$1 [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部署.我希望它对你有用.