Django 无法在 Hostmonster 中运行
我在 hostmonster 中设置了一个简单的 Django 项目: 项目名称为thep_viet,应用程序为mainapp 我的 .htaccess 是
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ django.fcgi/$1 [QSA,L]
我的 django.fcgi 是
#!/usr/bin/env python
# -*- mode: python; -*-
import sys, os
# Add a custom Python path.
sys.path.insert(0, "/home/riasolut/django/django_projects/")
# Switch to the directory of your project. (Optional.)
#os.chdir("/home/riasolut/django/django_projects/thep_viet")
# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ['DJANGO_SETTINGS_MODULE'] = "thep_viet.settings"
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
我成功设置 python 2.7.2 和 django 1.3.1
我在 ~/django/django_projects/ 中创建一个名为 thep_viet 的文件夹。该文件夹包含 thep_viet 项目的所有源代码。
我在 public_html 中创建一个名为 thep_viet 的文件夹,并将 .htaccess 和 django.fcgi 放入其中。 当我通过命令行运行 django.fcgi 时:
python ~/public_html/thep_viet/django.fcgi
我收到结果:
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!
Status: 200 OK
Content-Type: text/html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en"><head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="robots" content="NONE,NOARCHIVE"><title>Welcome to Django</title>
<style type="text/css">
html * { padding:0; margin:0; }
body * { padding:10px 20px; }
body * * { padding:0; }
body { font:small sans-serif; }
body>div { border-bottom:1px solid #ddd; }
h1 { font-weight:normal; }
h2 { margin-bottom:.8em; }
h2 span { font-size:80%; color:#666; font-weight:normal; }
h3 { margin:1em 0 .5em 0; }
h4 { margin:0 0 .5em 0; font-weight: normal; }
table { border:1px solid #ccc; border-collapse: collapse; width:100%; background:white; }
tbody td, tbody th { vertical-align:top; padding:2px 3px; }
thead th { padding:1px 6px 1px 3px; background:#fefefe; text-align:left; font-weight:normal; font-size:11px; border:1px solid #ddd; }
tbody th { width:12em; text-align:right; color:#666; padding-right:.5em; }
ul { margin-left: 2em; margin-top: 1em; }
#summary { background: #e0ebff; }
#summary h2 { font-weight: normal; color: #666; }
#explanation { background:#eee; }
#instructions { background:#f6f6f6; }
#summary table { border:none; background:transparent; }
</style>
</head>
<body>
<div id="summary">
<h1>It worked!</h1>
<h2>Congratulations on your first Django-powered page.</h2>
</div>
<div id="instructions">
<p>Of course, you haven't actually done any work yet. Here's what to do next:</p>
<ul>
<li>If you plan to use a database, edit the <code>DATABASES</code> setting in <code>thep_viet/settings.py</code>.</li>
<li>Start your first app by running <code>python thep_viet/manage.py startapp [appname]</code>.</li>
</ul>
</div>
<div id="explanation">
<p>
You're seeing this message because you have <code>DEBUG = True</code> in your
Django settings file and you haven't configured any URLs. Get to work!
</p>
</div>
</body></html>
看来 django 可以有效运行
但是当我在浏览器中运行时:
thepviet.mydomain.com
将 thepviet.mydomain.com 指向 mydomain.com/thep_viet
我收到 500 错误:
<!-- SHTML Wrapper - 500 Server Error -->
[an error occurred while processing this directive]
我是不是忘记了什么?我发现 hostmonster 的 apache 中的配置 fastcgi 有问题。
请帮助我的问题。
我阅读了错误日志并发现:
[Fri Nov 18 19:50:04 2011] [warn] [client 113.185.2.152] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
[Fri Nov 18 19:50:04 2011] [error] [client 113.185.2.152] Premature end of script headers: django.fcgi
[Fri Nov 18 19:50:04 2011] [error] [client 113.185.2.152] invalid CGI ref "/500.php" in /home4/riasolut/public_html/500.shtml
这个错误属于FastCGI服务器还是我的代码?
I had setup a simple Django project in hostmonster:
The project name is thep_viet, the app is mainapp
my .htaccess is
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ django.fcgi/$1 [QSA,L]
my django.fcgi is
#!/usr/bin/env python
# -*- mode: python; -*-
import sys, os
# Add a custom Python path.
sys.path.insert(0, "/home/riasolut/django/django_projects/")
# Switch to the directory of your project. (Optional.)
#os.chdir("/home/riasolut/django/django_projects/thep_viet")
# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ['DJANGO_SETTINGS_MODULE'] = "thep_viet.settings"
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
I'm setting python 2.7.2 and django 1.3.1 succesfully
I'm create a folder named thep_viet in ~/django/django_projects/. This folder contain all source code of thep_viet project.
I'm create a folder named thep_viet in public_html and place .htaccess and django.fcgi in this.
When I'm running django.fcgi by command line:
python ~/public_html/thep_viet/django.fcgi
I receive the result:
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!
Status: 200 OK
Content-Type: text/html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en"><head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="robots" content="NONE,NOARCHIVE"><title>Welcome to Django</title>
<style type="text/css">
html * { padding:0; margin:0; }
body * { padding:10px 20px; }
body * * { padding:0; }
body { font:small sans-serif; }
body>div { border-bottom:1px solid #ddd; }
h1 { font-weight:normal; }
h2 { margin-bottom:.8em; }
h2 span { font-size:80%; color:#666; font-weight:normal; }
h3 { margin:1em 0 .5em 0; }
h4 { margin:0 0 .5em 0; font-weight: normal; }
table { border:1px solid #ccc; border-collapse: collapse; width:100%; background:white; }
tbody td, tbody th { vertical-align:top; padding:2px 3px; }
thead th { padding:1px 6px 1px 3px; background:#fefefe; text-align:left; font-weight:normal; font-size:11px; border:1px solid #ddd; }
tbody th { width:12em; text-align:right; color:#666; padding-right:.5em; }
ul { margin-left: 2em; margin-top: 1em; }
#summary { background: #e0ebff; }
#summary h2 { font-weight: normal; color: #666; }
#explanation { background:#eee; }
#instructions { background:#f6f6f6; }
#summary table { border:none; background:transparent; }
</style>
</head>
<body>
<div id="summary">
<h1>It worked!</h1>
<h2>Congratulations on your first Django-powered page.</h2>
</div>
<div id="instructions">
<p>Of course, you haven't actually done any work yet. Here's what to do next:</p>
<ul>
<li>If you plan to use a database, edit the <code>DATABASES</code> setting in <code>thep_viet/settings.py</code>.</li>
<li>Start your first app by running <code>python thep_viet/manage.py startapp [appname]</code>.</li>
</ul>
</div>
<div id="explanation">
<p>
You're seeing this message because you have <code>DEBUG = True</code> in your
Django settings file and you haven't configured any URLs. Get to work!
</p>
</div>
</body></html>
It seem django can run effectly
But when I'm running in browser:
thepviet.mydomain.com
with thepviet.mydomain.com point to mydomain.com/thep_viet
I receive the 500 error:
<!-- SHTML Wrapper - 500 Server Error -->
[an error occurred while processing this directive]
Did I forget any thing? I thing something wrong in config fastcgi in apache of hostmonster.
Please help my problem.
I've read the error log and found:
[Fri Nov 18 19:50:04 2011] [warn] [client 113.185.2.152] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
[Fri Nov 18 19:50:04 2011] [error] [client 113.185.2.152] Premature end of script headers: django.fcgi
[Fri Nov 18 19:50:04 2011] [error] [client 113.185.2.152] invalid CGI ref "/500.php" in /home4/riasolut/public_html/500.shtml
Is this error belong to the FastCGI server or my code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
fcgi
文件中存在语法错误:daemonize
之前不应出现引号。正如 Jack M 在评论中所说,如果您查看服务器错误日志,您几乎肯定会在那里看到错误。
You have a syntax error in your
fcgi
file:The quote mark before
daemonize
shouldn't be there.As Jack M says in the comment, if you'd looked in the server error log, you would almost certainly see the error there.