1

我正在尝试学习如何使用 mod_wsgi 进行部署。我正在使用 django 1.4 和一个在 virtualenv 中运行的小应用程序

这是我的 apache2.conf 代码更改(ubuntu):

# https://docs.djangoproject.com/en/1.4/howto/deployment/wsgi/modwsgi/
# jcg 9/18/2012
WSGIScriptAlias / /home/jgoldstick/code/learn/myapp/wsgi.py
#WSGIPythonPath /home/jgoldstick/code/learn/myapp
WSGIPythonPath /home/jgoldstick/code/learn/myapp/lib/python2.7/site-packages

<Directory /home/jgoldstick/code/learn/myapp>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>

当我访问该网站时,我得到了 404 页。我正在使用 django 生成的标准 wsgi.py 脚本。

我错过了什么

更新更完整:这是我在 myapp/myapp 中的 wsgi.py 文件,我根据第一个答案添加了附件。

我在那个答案中假设 wsdl.py 真的意味着 wsgi.py。

import os, sys

sys.path.append('/home/jgoldstick/code/learn')
sys.path.append('/home/jgoldstick/code/learn/myapp')


os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)

我将 apache2.conf(我认为与 ubuntu 配置的 httpd.conf 相同)更改为:

https://docs.djangoproject.com/en/1.4/howto/deployment/wsgi/modwsgi/

# jcg 9/18/2012
Alias /media/ /home/jgoldstick/code/learn/media/

<Directory /home/jgoldstick/code/learn/media>
Order deny,allow
Allow from all
</Directory>

WSGIScriptAlias / /home/jgoldstick/code/learn/myapp/wsgi.py
WSGIPythonPath /home/jgoldstick/code/learn/myapp/lib/python2.7/site-packages

<Directory /home/jgoldstick/code/learn/myapp>
Order deny,allow
Allow from all
</Directory>

我重新启动了 apache 但是当我去我的应用程序时我仍然得到 404

4

1 回答 1

0

wsdl.py:

import os, sys
sys.path.append('/home/jgoldstick/code/learn')
sys.path.append('/home/jgoldstick/code/learn/myapp')
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

httpd.conf 应该是这样的:

Alias /media/ /home/jgoldstick/code/learn/media/

<Directory /home/jgoldstick/code/learn/media>
Order deny,allow
Allow from all
</Directory>

WSGIScriptAlias / /home/jgoldstick/code/learn/myapp/django.wsgi
WSGIPythonPath /home/jgoldstick/code/learn/myapp/lib/python2.7/site-packages

<Directory /home/jgoldstick/code/learn/myapp>
Order deny,allow
Allow from all
</Directory>

如果django.wsgi位于/home/jgoldstick/code/learn/myapp/myapp/django.wsgi/myapp到处添加。

/media/与目录相同的配置应该有static并且记得执行./manage.py collectstatic

请参考文档 Django-modWSGI

于 2012-09-18T18:46:43.010 回答