django - 在 Centos 7 中使用 apache + mod_wsgi + django 激活 virtualenv 的权限被拒绝

标签 django apache centos virtualenv mod-wsgi

我什至不知道我尝试了多少次使用 apachemod_wsgi 部署 django 应用程序,但仍然一次又一次遇到相同的错误,这是 wsgi.py 文件:

"""
WSGI config for progress_bar 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.7/howto/deployment/wsgi/
"""

import os
import sys
import site

# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('/home/tone/entornos/progressbar/lib/python2.7/site-packages')


sys.path.append('/var/www/html/progress_bar/progress_bar')
sys.path.append('/var/www/html/progress_bar')


# Add virtualenv and activate for apache
    activate_env=os.path.expanduser("/home/tone/entornos/progressbar/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "progress_bar.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

虚拟主机配置:

<VirtualHost *:80>
   #WSGIDaemonProcess python-path=/home/tone/entornos/progressbar/lib/python2.7/site-packages
   #WSGIPythonPath /home/tone/entornos/progressbar/bin:/home/tone/entornos/progressbar/lib/python2.7/site-packages

   WSGIScriptAlias /progress-django-upload /var/www/html/progress_bar/progress_bar/wsgi.py

   <Directory /var/www/html/progress_bar>
      Require all granted
   </Directory>
</VirtualHost>

但我总是尝试访问,但我有一个很好的错误 500 并且日志显示相同的内容:

    [Fri Mar 13 13:19:12.427639 2015] [:error] [pid 4217] [client 150.214.108.153:50376] mod_wsgi (pid=4217): Target WSGI script '/var/www/html/progress_ba$
    [Fri Mar 13 13:19:12.427799 2015] [:error] [pid 4217] [client 150.214.108.153:50376] mod_wsgi (pid=4217): Exception occurred processing WSGI script '/v$
    [Fri Mar 13 13:19:12.427894 2015] [:error] [pid 4217] [client 150.214.108.153:50376] Traceback (most recent call last):
    [Fri Mar 13 13:19:12.427981 2015] [:error] [pid 4217] [client 150.214.108.153:50376]   File "/var/www/html/progress_bar/progress_bar/wsgi.py", line 24,$
    [Fri Mar 13 13:19:12.428421 2015] [:error] [pid 4217] [client 150.214.108.153:50376]     execfile(activate_env, dict(__file__=activate_env))
    [Fri Mar 13 13:19:12.428567 2015] [:error] [pid 4217] [client 150.214.108.153:50376] IOError: [Errno 13] Permission denied: '/home/tone/entornos/progre$
    [Fri Mar 13 13:19:14.450602 2015] [:error] [pid 4216] [client 150.214.108.153:50377] mod_wsgi (pid=4216): Target WSGI script '/var/www/html/progress_ba$
    [Fri Mar 13 13:19:14.450722 2015] [:error] [pid 4216] [client 150.214.108.153:50377] mod_wsgi (pid=4216): Exception occurred processing WSGI script '/v$
    [Fri Mar 13 13:19:14.450811 2015] [:error] [pid 4216] [client 150.214.108.153:50377] Traceback (most recent call last):
    [Fri Mar 13 13:19:14.450889 2015] [:error] [pid 4216] [client 150.214.108.153:50377]   File "/var/www/html/progress_bar/progress_bar/wsgi.py", line 24,$
    [Fri Mar 13 13:19:14.451162 2015] [:error] [pid 4216] [client 150.214.108.153:50377]     execfile(activate_env, dict(__file__=activate_env))
    [Fri Mar 13 13:19:14.451249 2015] [:error] [pid 4216] [client 150.214.108.153:50377] IOError: [Errno 13] Permission denied: '/home/tone/entornos/progre$

在你回答之前...是的,我使用chown -R apache:apache/home/tone/entornos/progressbar/bin为apache设置了权限,甚至设置为activate_this.py code> 到 chomd 777 ... 甚至暂时禁用 SELinux,什么也没有...权限始终相同...有人有解决这个问题的魔杖吗?

问候!

最佳答案

最后sudo chmod -R 755/home/tone完成了工作!我不知道这样做是否是一个好的做法,只需授予所有组读取和执行整个主目录的权限,但目前这是一个很好的解决方法。

关于django - 在 Centos 7 中使用 apache + mod_wsgi + django 激活 virtualenv 的权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29032412/

相关文章:

django memcached on red hat

dns - 百胜错误 - centos 7.1 x86_64

python - 如何从上下文处理器获取当前应用程序名称?

python - Django 管理命令未正确导入

mysql - 在 Mac 操作系统上安装 Hive-2.1.1 出现错误 ‘Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient’

regex - 使用 htaccess 将路径目录附加到 url

apache - 比较Nginx + Apache + mod_wsgi和Nginx + uWSGI?

python - Django - 从 ModelForm 获取模型对象属性

python - 为什么添加这个 __init__() 方法会破坏我的 Django 模型?

python - 如何使用 Python 下载文件?