【问题标题】:django using fcgi in shared hostingdjango 在共享主机中使用 fcgi
【发布时间】:2014-10-24 11:36:56
【问题描述】:

我正在尝试检查我的主机是否支持我的 django 站点所需的内容,因此 atm 我正在尝试设置一个基本的 django 站点。 使这更加复杂的是我需要从同一台服务器上运行另一个 joomla 页面(见下文)。 我不知道我是否做错了什么(很可能)以及我应该向主持人询问什么。 (我知道我在这方面有点菜鸟)

这是我目前所拥有的: 在 /home/username/

  1. library-site/

    • lib/
      • manage.py
      • lib/
        • settings.py
        • ...
  2. 公共-html/

    • cgi-bin
    • 文件夹包含_joomla_site
    • 图书馆
    • bin
    • ...

(按照指南,我已将 virtualenv 的站点包符号链接到 library_site/lib)

我不得不说我已经尝试了很多指南,所以很难展示整个图片,但这是我现在所拥有的

在 public_html/library/dispatch.fcgi 中

#!/home/username/library/bin/python

import sys
import os

sys.path.insert(0, "/home/username/library/bin/python")
sys.path.append('/home/username/library/lib/python2.6/site-packages')
sys.path.insert(13, "/home/username/public_html/library")

open("/home/username/public_html/library/cgi.log", "w").write("Before try")

try:
    os.environ['DJANGO_SETTINGS_MODULE'] = 'lib.settings'
    from django.core.servers.fastcgi import runfastcgi
    runfastcgi(method="threaded", daemonize="false")
except Exception:
    open("/home/username/public_html/library/cgi.log", "w").write(format_exc())
    raise

在 public_html/library/.htaccess 中

AddHandler fcgid-script .fcgi
Options +FollowSymLinks
RewriteEngine On
  RewriteBase /library/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(dispatch\.fcgi/.*)$ - [L]
  RewriteRule ^(.*)$ dispatch.fcgi/$1 [L]

像这样导航到http://example.com/library 会显示文件夹的内容。点击dispatch.fcgi只显示python代码。

从 ./dispatch.fcgi 运行返回正确的 django 输出,但前四行读取

WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!

这些都告诉我,我需要向主人询问一些事情,但我现在不知道什么。

还有,正在运行

python ~/library_site/lib/manage.py runfcgi daemonize=false host=127.0.0.1 port=3033 maxrequests=1

这里推荐:https://twiki.cern.ch/twiki/bin/view/ITCF/DjangoGeneral 不会返回任何问题。

最后,启动 django 服务器:

python manage.py runserver 0.0.0.0:8000

工作正常。有人可以帮忙吗?

【问题讨论】:

  • 您确定您的服务器尊重 .htaccess 吗?必须专门启用它,并且您的 URL 似乎根本没有被重写。

标签: python django .htaccess fastcgi


【解决方案1】:

FCGI 需要在它和 WSGI 之间建立一个转换层。确保您已安装 flup 并且您的 FCGI 文件是可执行的

Here is a guide大约两年前我就可以开始工作了。

【讨论】:

  • 你真的是想说“UWSGI”吗?他们不使用 uWSGI 也不依赖于 uwsgi 二进制有线协议。所以怀疑你的意思是“WSGI”。
  • 不,打字是一种习惯。
  • 确实问题似乎是 .fcgi 文件不可执行。放到cgi-bin文件夹就解决了问题
【解决方案2】:

我现在觉得有点愚蠢,因为答案真的很琐碎。按照本指南http://joemaller.com/1467/django-via-cgi-on-shared-hosting/,我已将 .fcgi 放入 cgi-bin 并在 public_html 中编写了适当的 .htaccess 文件......瞧!

作为将来尝试此操作的任何人的兴趣点,关于静态文件(这更加痛苦),我已将它们放在“public_html/library/static/”中(

【讨论】:

    猜你喜欢
    • 2015-05-27
    • 2011-07-01
    • 1970-01-01
    • 2012-09-28
    • 1970-01-01
    • 1970-01-01
    • 2016-02-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多