【发布时间】:2014-12-19 11:31:40
【问题描述】:
我最近一直在尝试在 CentOS 服务器上使用 mod_wsgi 部署 Django 站点,但到目前为止,当我尝试通过笔记本电脑访问 django 站点时,网页只显示 error: 403 Forbidden You don't have permission to access / on this server.
除了阅读所有明显的文档之外,我还查看了这些以前的问题:
- Django + mod_wsgi + Apache = 403 Forbidden
- Error message “Forbidden You don't have permission to access / on this server”
- Forbidden You don't have permission to access / on this server
- Apache mod_wsgi error: Forbidden You don't have permission to access / on this server
- Django on apache wtih mod_wsgi (Linux) - 403 Forbidden
环境:
-
Centos 6.5 -
Python 2.6 -
Django 1.6
我正在运行以下版本的 apache:
# 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)
我使用 Yum 安装了 mod_wsgi 并确认它已安装在服务器上:
# httpd -M | grep wsgi
wsgi_module (shared)
Syntax OK
我的httpd.conf wsgi config sn -p 如下:
#
# 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.py 脚本是:
"""
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()
错误日志的输出:
[Fri Oct 24 14:10:43 2014] [error] [client (redacted)] Symbolic link not allowed or link target not accessible: /usr/local/django/basic
[Fri Oct 24 14:11:25 2014] [error] [client (redacted)] Symbolic link not allowed or link target not accessible: /usr/local/django/basic
[Fri Oct 24 14:14:02 2014] [error] [client (redacted)] Symbolic link not allowed or link target not accessible: /usr/local/django/basic
注意事项:
- django 项目位于我用户的主目录中,但在 `/usr/local/django/ 中有一个符号链接指向它
- 过去我在项目中工作时,错误 403 通常意味着文件的权限错误,但我已经检查过,文件应该都允许 apache 用户访问它们
- 当我注释掉 Apache 配置的 wsgi 相关行时,我的 Web 服务器工作正常。
【问题讨论】:
标签: python linux django apache mod-wsgi