[英]Apache mod_wsgi throwing error “403 Forbidden” when deploying a Django project
I have been trying to deploy a Django site using mod_wsgi
on a CentOS server recently, but so far when I try to access the django site through my laptop, the web page has only been displaying error: 403 Forbidden You don't have permission to access / on this server.
我最近一直在尝试在CentOS服务器上使用mod_wsgi
部署Django站点,但是到目前为止,当我尝试通过笔记本电脑访问django站点时,该网页仅显示error: 403 Forbidden You don't have permission to access / on this server.
In addition to reading all the obvious documentation, I have looked at these previous questions: 除了阅读所有显而易见的文档之外,我还研究了以下先前的问题:
Environment: 环境:
Centos 6.5
Python 2.6
Django 1.6
I am running the following version of apache: 我正在运行以下版本的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)
I installed mod_wsgi
using Yum and have confirmed it is installed on the server: 我使用Yum安装了mod_wsgi
,并确认它已安装在服务器上:
# httpd -M | grep wsgi
wsgi_module (shared)
Syntax OK
My httpd.conf wsgi config snippet is as follows: 我的httpd.conf wsgi配置代码段如下:
#
# 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>
Finally my wsgi.py script is: 最后,我的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()
Output from error log: 错误日志的输出:
[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
Notes: 笔记:
Sorry, that I posted this a bit late. 抱歉,我发布得晚了一点。 This was the final fix to my apache config that ultimately worked. 这是对我的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
And this is the final version of my wsgi.py file in python. 这是python中wsgi.py文件的最终版本。 The key line of code here was the PYTHON_EGG_CACHE
. 此处的关键代码行是PYTHON_EGG_CACHE
。 That variable was by default set to a directory that did not exist. 默认情况下,该变量设置为不存在的目录。 I set it to /tmp/.python-eggs
Make sure that .python-eggs
has correct permissions for the apache user to read/write to it wherever you may place this file. 我将其设置为/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()
Side note: 边注:
May be you forget set DocumentRoot. 可能是您忘记了设置DocumentRoot。 You should make the DocumentRoot can be read and wrote by apache users. 您应该使DocumentRoot可以被apache用户读取和写入。 just do like this: 就是这样:
sudo chown -R www_default:www_default /path/to/you/DocumentRoot
and you can also do like this : 而且您也可以这样:
sudo chmod -R 755 /path/to/your/DocumentRoot
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.