我什至不知道我尝试了多少次使用 apache
和 mod_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/