Django + Apache + mod_wsgi permission denied

时间:2022-09-17 07:52:51

I finished the tutorial on Django's site about using mod_wsgi (here), and having substituted my paths as appropriate, results in a big fat "Permission denied." when I try to access /. Here is the stuff I added to httpd.conf (mod_wsgi is enabled earlier in the conf file):

我在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>

Edit #1:

编辑#1:

I've gone through the slides multiple times, from the start: still no joy. Even after opening up the path to the script, chmod'ing every relevant directory to be readable, and chmod'ing the .wsgi script, I still get permission denied. If I change the directory path from /usr/local/django/billing/apache/django.wsgi to have the django.wsgi truncated, the server returns a configuration error, despite that being how it's configured in the slides.

我从头开始多次浏览幻灯片:仍然没有快乐。即使打开了脚本的路径,chmod'ing每个相关目录是可读的,并chmod'ing .wsgi脚本,我仍然得到权限否认。如果我从/usr/local/django/billing/apache/django.wsgi更改目录路径以截断django.wsgi,则服务器会返回配置错误,尽管它是如何在幻灯片中配置的。

3 个解决方案

#1


6  

I had the same problem with permission denied. https://serverfault.com/questions/357804/apache2-mod-wsgi-django-named-virtual-servers

我有同样的问题,拒绝许可。 https://serverfault.com/questions/357804/apache2-mod-wsgi-django-named-virtual-servers

The specific error is described in: http://code.google.com/p/modwsgi/wiki/WhereToGetHelp?tm=6#Conference_Presentations

具体错误描述如下:http://code.google.com/p/modwsgi/wiki/WhereToGetHelp?tm = 6#Conference_Presentations

#2


14  

Same configuration, same environment... but everything was working except a simple call to Popen() in one of my django/python routines...

相同的配置,相同的环境...但除了在我的django / python例程中对Popen()的简单调用之外,一切正常...

"Permission denied"

“没有权限”

Turned out to be SELINUX (enforcing mode) blocking apache.

原来是SELINUX(强制模式)阻止apache。

You can make SELINUX happy with your application by running the following commands:

您可以通过运行以下命令使SELINUX满意您的应用程序:

# semanage fcontext -a -t httpd_sys_rw_content_t '/path/to/your/app(/.*)?'
# restorecon -R -v /path/to/your/app

#3


4  

I had the same issue,Sometimes this happends if the WSGI application is located outside of any directories already configured to be accessible to Apache, particularly when it is on your home directory, its good to specify user=username directive.

我遇到了同样的问题,如果WSGI应用程序位于已经配置为Apache可访问的任何目录之外,有时会出现这种情况,特别是当它位于您的主目录中时,指定user = username指令是很好的。

/etc/apahe2/sites-avaliable/myvhost [section]

/ etc / apahe2 / sites-avaliable / myvhost [section]

WSGIDaemonProcess localhost python-path=/home/hemanth/ecm:/home/env/lib/python2.7/site-packages  user=hemanth
WSGIProcessGroup localhost

/etc/apahe2/sites-avaliable/myvhost [full]

/ 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>

index.wsgi

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()

#1


6  

I had the same problem with permission denied. https://serverfault.com/questions/357804/apache2-mod-wsgi-django-named-virtual-servers

我有同样的问题,拒绝许可。 https://serverfault.com/questions/357804/apache2-mod-wsgi-django-named-virtual-servers

The specific error is described in: http://code.google.com/p/modwsgi/wiki/WhereToGetHelp?tm=6#Conference_Presentations

具体错误描述如下:http://code.google.com/p/modwsgi/wiki/WhereToGetHelp?tm = 6#Conference_Presentations

#2


14  

Same configuration, same environment... but everything was working except a simple call to Popen() in one of my django/python routines...

相同的配置,相同的环境...但除了在我的django / python例程中对Popen()的简单调用之外,一切正常...

"Permission denied"

“没有权限”

Turned out to be SELINUX (enforcing mode) blocking apache.

原来是SELINUX(强制模式)阻止apache。

You can make SELINUX happy with your application by running the following commands:

您可以通过运行以下命令使SELINUX满意您的应用程序:

# semanage fcontext -a -t httpd_sys_rw_content_t '/path/to/your/app(/.*)?'
# restorecon -R -v /path/to/your/app

#3


4  

I had the same issue,Sometimes this happends if the WSGI application is located outside of any directories already configured to be accessible to Apache, particularly when it is on your home directory, its good to specify user=username directive.

我遇到了同样的问题,如果WSGI应用程序位于已经配置为Apache可访问的任何目录之外,有时会出现这种情况,特别是当它位于您的主目录中时,指定user = username指令是很好的。

/etc/apahe2/sites-avaliable/myvhost [section]

/ etc / apahe2 / sites-avaliable / myvhost [section]

WSGIDaemonProcess localhost python-path=/home/hemanth/ecm:/home/env/lib/python2.7/site-packages  user=hemanth
WSGIProcessGroup localhost

/etc/apahe2/sites-avaliable/myvhost [full]

/ 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>

index.wsgi

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()