我最近在CentOS服务器上尝试使用mod_wsgi
部署Django网站,但到目前为止,当我尝试通过笔记本电脑访问django网站时,网页只显示{{1} }
除了阅读所有明显的文档外,我还看了以前的这些问题:
环境:
error: 403 Forbidden You don't have permission to access / on this server.
Centos 6.5
Python 2.6
我正在运行以下版本的apache:
Django 1.6
我使用Yum安装了# apachectl -V
Server version: Apache/2.2.15 (Unix)
Server built: Apr 3 2014 23:56:16
Server's Module Magic Number: 20051115:25
Server loaded: APR 1.3.9, APR-Util 1.3.9
Compiled using: APR 1.3.9, APR-Util 1.3.9
Architecture: 64-bit
Server MPM: Prefork
threaded: no
forked: yes (variable process count)
,并确认它已安装在服务器上:
mod_wsgi
我的httpd.conf wsgi配置片段如下:
# httpd -M | grep wsgi
wsgi_module (shared)
Syntax OK
最后我的wsgi.py脚本是:
#
# Add WSGI configuration
#
WSGIScriptAlias / /usr/local/django/basic/basic/apache/wsgi.py
WSGIPythonPath /usr/local/django/basic/
WSGIDaemonProcess ###.###.###.###
WSGIProcessGroup ###.###.###.###
<Directory /usr/local/django/basic/basic/apache>
<Files wsgi.py>
Options FollowSymLinks
Order deny,allow
Allow from all
</Files>
</Directory>
错误日志输出:
"""
WSGI config for basic project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
"""
import os
import sys
path = "/usr/local/django/basic/basic/apache"
if path not in sys.path:
sys.path.append(path)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "basic.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
注意:
答案 0 :(得分:1)
抱歉,我发布的有点迟了。这是我的apache配置的最终修复,最终有效。
WSGIScriptAlias /basic /var/www/django/basic/basic/wsgi.py
WSGIPythonPath /var/www/django/basic/
<Directory /var/www/django/basic/basic>
Options FollowSymLinks
<Files wsgi.py>
Order allow,deny
Allow from all
</Files>
</Directory>
Alias /static /var/www/django/basic/basic/static
这是我在python中的wsgi.py文件的最终版本。这里的关键代码是PYTHON_EGG_CACHE
。默认情况下,该变量设置为不存在的目录。我将其设置为/tmp/.python-eggs
确保.python-eggs
具有正确的权限,以便apache用户可以在任何位置读取/写入该文件。
"""
WSGI config for basic project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
"""
import os
import sys
path = "/usr/local/django/basic/basic/apache"
if path not in sys.path:
sys.path.append(path)
os.environ['PYTHON_EGG_CACHE'] = '/tmp/.python-eggs'
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "basic.settings")
#print os.getenv("DJANGO_SETTINGS_MODULE")
#print os.getenv("PYTHON_EGG_CACHE")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
旁注:
答案 1 :(得分:0)
可能是你忘了设置DocumentRoot。你应该让apache用户可以读取和编写DocumentRoot。 就这样做:
sudo chown -R www_default:www_default /path/to/you/DocumentRoot
你也可以这样做:
sudo chmod -R 755 /path/to/your/DocumentRoot