带有 FCGI 的 Apache 上的 Django

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1696308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 18:23:10  来源:igfitidea点击:

Django on Apache with FCGI

djangoapachefastcgi

提问by Peter Horne

Solved:Unfortunately I wasn't able to solve the problem but I started over and followed the Django + FastCGI guideon the "A Small Orange" wikiand everything is working as expected.

已解决:不幸的是,我无法解决问题,但我重新开始并遵循“A Small Orange”wiki上的Django + FastCGI 指南,一切都按预期工作。

I am trying to setup Django with FCGI on Apache. The web hosting plan that I am using is A Small Orange's shared hosting plan.

我正在尝试在 Apache 上使用 FCGI 设置 Django。我使用的网络托管计划是 A Small Orange 的共享托管计划。

Django is installed, working and is able to create database tables when I run the syncdb command. If I run manage.py runserverand then use lynx to navigate to localhost:8080django will correctly display. However, It is not possible to view django over the internet as the page displays a 500 internal server error.

当我运行 syncdb 命令时,Django 已安装、工作并且能够创建数据库表。如果我运行manage.py runserver然后使用 lynx 导航到localhost:8080django 将正确显示。但是,由于页面显示 500 内部服务器错误,因此无法通过 Internet 查看 django。

I have the flup python package installed and am using python version 2.6.

我安装了 flup python 包并且使用的是 python 2.6 版。

The following is the contents of my .htaccess file that is situated in /public_html/:

以下是我位于的 .htaccess 文件的内容/public_html/

RewriteEngine On
  RewriteBase /
  RewriteRule ^(media/.*)$ - [L]
  RewriteRule ^(admin_media/.*)$ - [L]
  RewriteRule ^(dispatch\.fcgi/.*)$ - [L]
  RewriteRule ^(.*)$ dispatch.fcgi/ [L]

The following is the contents of my dispatch.fcgi file that is also located in /public_html:

以下是我的 dispatch.fcgi 文件的内容,该文件也位于/public_html

#!/usr/local/lib/python2.6
import sys
import os
os.chdir('/home/thegamer/django/projects/thegamer')
sys.path += ['/home/thegamer/django/django']
sys.path += ['/home/thegamer/django/projects']
from fcgi import WSGIServer
from django.core.handlers.wsgi import WSGIHandler
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'thegamer.settings'
WSGIServer(WSGIHandler()).run()

采纳答案by Peter Horne

Starting again and following the Django + FastCGI guideon the "A Small Orange" wikiresulted in everything working as expected.

重新开始并遵循“A Small Orange”wiki上的Django + FastCGI 指南,结果一切都按预期工作。

回答by Rasmus Kaj

Are you using sqlite? If so, you need an absolute path for the db file, not a relative.

你在用sqlite吗?如果是这样,您需要 db 文件的绝对路径,而不是相对路径。

If thats not it, set DEBUG=True in your settings and let django tell you what it is.

如果不是这样,请在您的设置中设置 DEBUG=True 并让 django 告诉您它是什么。

回答by Ben Hodgson

I just had this exact same problem. It took some time but I was finallyable to resolve it with assistance from A Small Orange's (very helpful!) support guys.

我刚刚遇到了完全相同的问题。这花了一些时间,但我终于能够在小橙子(非常有帮助!)支持人员的帮助下解决它。

You need to make sure that your dispatch.fcgifile is chmod'ed to 755. Anything else (mine was 775) will cause this error.

你需要确保你的dispatch.fcgi文件被chmod修改为 755。其他任何东西(我的是 775)都会导致这个错误。