gpt4 book ai didi

python - 使用 fastcgi 在共享主机上设置的 Pyramid 将 .fcgi 文件返回给浏览器

转载 作者:太空宇宙 更新时间:2023-11-03 11:48:21 25 4
gpt4 key购买 nike

任何人都可以帮助我在带有 Pyramid 的共享主机上设置生产服务器的过程吗?我搜索了一整天,试图让这项工作奏效,但没有任何效果。

我在编写 .htaccess 和 index.fcgi 文件时遇到问题。我试图结合这些教程; 1 , 2 , 3 , 4弄清楚但是当我访问该网站时,我看到了 index.fcgi 的内容而不是应用程序。我已经完成了这些步骤;

  1. 在主目录中为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
  2. 在虚拟环境中安装 Pyramid 。

    pip install pyramid
  3. 创建了一个测试项目;

    pcreate -s starter myProject
    cd myProject
    python setup.py install
  4. 已安装 flup

    pip install flup
  5. 在我的 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()
  6. 使 index.fcgi 可执行;

    cd public_html
    chmod +x index.fcgi

    它的权限是0755。

  7. 将 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 部署.希望对您有用。

关于python - 使用 fastcgi 在共享主机上设置的 Pyramid 将 .fcgi 文件返回给浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33899415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com