pat*_*ckn 4 apache django mod-wsgi
我在Django的网站上完成了关于使用mod_wsgi(这里)的教程,并且在适当的时候替换了我的路径,导致了很大的"权限被拒绝".当我尝试访问/.这是我添加的东西httpd.conf(mod_wsgi在conf文件的早期启用):
# Django configuration
WSGIScriptAlias / /usr/local/django/billing/apache/django.wsgi
<Directory /usr/local/django/billing/apache/django.wsgi>
Order allow,deny
Allow from all
</Directory>
AliasMatch ^/([^/]*\.css) /usr/local/wsgi/static/styles/$1
Alias /media/ /usr/local/django/billing/media/
Alias /static/ /usr/local/django/billing/static/
<Directory /usr/local/django/billing/static>
Order deny,allow
Allow from all
</Directory>
<Directory /usr/local/django/billing/media>
Order deny,allow
Allow from all
</Directory>
Run Code Online (Sandbox Code Playgroud)
编辑#1:
我从头开始多次浏览幻灯片:仍然没有快乐.即使打开了脚本的路径,chmod'ing每个相关的目录是可读的,并chmod'ing .wsgi脚本,我仍然得到权限否认.如果我改变从目录路径/usr/local/django/billing/apache/django.wsgi有django.wsgi截断,服务器尽管是它是如何在幻灯片中配置返回配置错误.
小智 16
相同的配置,相同的环境......但除了在我的django/python例程中对Popen()的简单调用外,一切正常...
"没有权限"
原来是SELINUX(强制模式)阻止apache.
您可以通过运行以下命令使SELINUX满意您的应用程序:
# semanage fcontext -a -t httpd_sys_rw_content_t '/path/to/your/app(/.*)?'
# restorecon -R -v /path/to/your/app
Run Code Online (Sandbox Code Playgroud)
我遇到了同样的问题,如果WSGI应用程序位于已经配置为Apache可访问的任何目录之外,有时会发生这种情况,特别是当它位于您的主目录时,指定user = username指令是很好的.
/ etc/apahe2/sites-avaliable/myvhost [section]
WSGIDaemonProcess localhost python-path=/home/hemanth/ecm:/home/env/lib/python2.7/site-packages user=hemanth
WSGIProcessGroup localhost
Run Code Online (Sandbox Code Playgroud)
/ etc/apahe2/sites-avaliable/myvhost [full]
<VirtualHost *:80>
ServerAdmin xy@gmail.om
ServerName localhost
ServerAlias localhost
DocumentRoot /home/hemanth/ecm
<Directory /home/hemanth/ecm>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias / /home/hemanth/ecm/index.wsgi
WSGIDaemonProcess localhost python-path=/home/hemanth/ecm:/home/env/lib/python2.7/site-packages user=hemanth
WSGIProcessGroup localhost
Alias /static/ /home/hemanth/ecm/static/
Alias /media/ /home/hemanth/ecm/media/
<Directory /home/hemanth/ecm/media/>
Order allow,deny
Allow from all
</Directory>
<Location "/static/">
Options -Indexes
</Location>
ErrorLog /home/hemanth/ecm/error.log
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
index.wsgi
import os
import sys
import site
# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('/home/hemanth/env/local/lib/python2.7/site-packages')
# Add the app's directory to the PYTHONPATH
sys.path.append('/home/hemanth/ecm')
sys.path.append('/home/hemanth/ecm/ecm')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ecm.settings")
# Activate your virtual env
activate_env="/home/hemanth/env/bin/activate_this.py"
execfile(activate_env, dict(__file__=activate_env))
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22809 次 |
| 最近记录: |