使用 passenger_wsgi.py 托管 Django

Hosting Django with passenger_wsgi.py

我在使用 python passenger_wsgi.py 和虚拟环境在 dreamhost 共享主机上设置我的 django 时遇到问题。当我 运行 passenger_wsgi.py 没有返回错误并且 shell 打印我的项目路径。我的网站显示 500 国际服务器错误。我已经清除了缓存,所以没有缓存错误。我该如何正确设置?

django 1.9 python 2.7 阿帕奇

我的网站结构是:

/home/myuser/mydomain.com/
   env/
   myApp/
   passenger_wsgi.py
   public/

passenger_wsgi.py

import sys, os
cwd = os.getcwd()
sys.path.append(cwd)

project_location = cwd + '/myApp'
print (project_location)
sys.path.insert(0, project_location)

#Switch to new python
if sys.version < "2.7.3": os.execl("/home/myuser/mydomain.com/env/bin/python",
"python2.7.3", *sys.argv)

sys.path.insert(0,'/home/myuser/mydomain.com/env/bin')
sys.path.insert(0,'/home/myuser/mydomain.com/env/lib/python2.7/site-packages/django')
sys.path.insert(0,'/home/myuser/mydomain.com/env/lib/python2.7/site-packages')


os.environ['DJANGO_SETTINGS_MODULE'] = "myApp.settings"

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

我在从 Django 1.6 升级到 1.8 时特别遇到 Dreamhost 问题。问题之一是 WSGIHandler()。我不能说这是你的问题,但你可以尝试像这样设置 application

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

最后 - 确保重启 passenger。这里有关于如何操作的文档:http://wiki.dreamhost.com/Passenger

来自该页面:

Whenever the code or configuration files for your application are modified, you must create or update the modification date of the file "tmp/restart.txt" in the application's root directory tree in order to trigger Passenger to reinitialize the application. Passenger caches many resources so changes are not recognized unless the modification date of "tmp/restart.txt" is changed.

The most common method to make this change is to run "touch tmp/restart.txt" via SSH. (Ruby on Rails automatically creates a directory named "tmp". If you are creating non-RoR application, you may need to create the "tmp" directory manually.