2013-12-13 200 views
0

我真的花了我所有的一天设置我的Django应用程序运行在我的BlueHost共享主机上。我的.htaccessmysite.fcgi文件位于域根目录中,而不是帐户根目录,这意味着我有一个指向public_html/mysite目录的网站MySite.com,因此上述两个文件位于public_html/mysite文件夹下。Django共享主机设置

的.htaccess

AddHandler fastcgi-script .fcgi 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ /mysite/mysite.fcgi/$1 [NC,L,QSA] 

mysite.fcgi

#!/home1/username/myvirtualenv/bin/python 
import sys, os 

# Add a custom Python path. 
sys.path.insert(0, "/home1/username/myvirtualenv/bin/python") 
sys.path.insert(13, "/home1/username/www/mysite") 

open("/home1/username/public_html/mysite/cgi.log", "w").write("Before try") 

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

,当我通过ssh运行./mysite.fgci:

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 
X-Frame-Options: SAMEORIGIN 
Content-Type: text/html; charset=utf-8 

HTML here 

,当我访问mysite.com在浏览器:

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace. 

任何帮助,高度赞赏!

回答

0

尝试

sys.path.append("/home1/username/www/mysite") 

更换

sys.path.insert(13, "/home1/username/www/mysite") 

希望它能帮助。

0

这个答案有点晚,但我希望它对其他人有用。

接下来是我的.htaccess和django.fcgi文件。 这些文件在JustHost中正常工作。 注意第一行和最后一行的差异 我不知道BlueHost的配置是否相同。

AddHandler fcgid-script .fcgi 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ django.fcgi/$1 [QSA,L] 

这里假设.fcgi和.htaccess文件位于同一个目录中。 但在你的情况下,你可以适应最后一行。

我使用的是简约.fcgi文件(django.fcgi在我的情况)

#!/home/.../venv/bin/python 
# DO NOT USE SOMETHING LIKE THIS #!/usr/bin/env python 
import sys, os 

# Add a custom Python path. 
sys.path.insert(0, "/home/.../django_project_directory") 

# Set the DJANGO_SETTINGS_MODULE environment variable. 
os.environ['DJANGO_SETTINGS_MODULE'] = "my_project_name.settings" 

from django.core.servers.fastcgi import runfastcgi 
runfastcgi(method="threaded", daemonize="false")