关注烧瓶的文档:
http://flask.pocoo.org/docs/0.12/deploying/mod_wsgi/
的Apache / 2.4.10 烧瓶0.12.2
目录结构:
├── movie_douban.py
├── movie_douban.wsgi
└── app
├── web
├── models
├── templates
└── static
movie_douban.wsgi:
activate_this='/root/.local/share/virtualenvs/movie_douban-og6kh8C1/bin/activate_this.py'
with open(activate_this) as file_:
exec(file_.read(), dict(__file__=activate_this))
import sys
sys.path.insert(0, '/root/.local/share/virtualenvs/movie_douban-og6kh8C1/lib/python3.4/site-packages/')
from movie_douban import app as application
的Apache:
<VirtualHost *:80>
ServerName gdd.python.com
WSGIDaemonProcess movie_douban user=www-data group=www-data threads=5
WSGIScriptAlias / /var/www/movie_douban/movie_douban.wsgi
ErrorLog "/private/var/log/apache2/python-error_log"
<Directory /var/www/movie_douban>
WSGIProcessGroup movie_douban
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
</VirtualHost>
Apache错误:
[Sun Apr 29 10:59:56.835279 2018] [wsgi:error] [pid 16942] [remote 172.17.0.1:50790] mod_wsgi (pid=16942): Target WSGI script '/var/www/movie_douban/movie_douban.wsgi' cannot be loaded as Python module.
[Sun Apr 29 10:59:56.835321 2018] [wsgi:error] [pid 16942] [remote 172.17.0.1:50790] mod_wsgi (pid=16942): Exception occurred processing WSGI script '/var/www/movie_douban/movie_douban.wsgi'.
[Sun Apr 29 10:59:56.835470 2018] [wsgi:error] [pid 16942] [remote 172.17.0.1:50790] Traceback (most recent call last):
[Sun Apr 29 10:59:56.835603 2018] [wsgi:error] [pid 16942] [remote 172.17.0.1:50790] File "/var/www/movie_douban/movie_douban.wsgi", line 2, in <module>
[Sun Apr 29 10:59:56.837206 2018] [wsgi:error] [pid 16942] [remote 172.17.0.1:50790] with open(activate_this) as file_:
[Sun Apr 29 10:59:56.837265 2018] [wsgi:error] [pid 16942] [remote 172.17.0.1:50790] IOError: [Errno 13] Permission denied: '/root/.local/share/virtualenvs/movie_douban-og6kh8C1/bin/activate_this.py'
root@345ad0ab8386:/var/www/movie_douban# ls -l /root/.local/share/virtualenvs/movie_douban-og6kh8C1/bin/activate_this.py
-rwxrwxrwx 1 root root 1137 Apr 28 03:31 /root/.local/share/virtualenvs/movie_douban-og6kh8C1/bin/activate_this.py
我该怎么办?
答案 0 :(得分:0)
权限被拒绝错误通常是由要加载的文件的所有者,组或文件模式设置不正确或导致它的一个子目录引起的。另一个可能的原因是SELinux,但只有在启用并处于强制模式时才会出现。
Permission denied: '/root/.local/share/virtualenvs/movie_douban-og6kh8C1/bin/activate_this.py'
在这种情况下,几乎可以肯定Apache进程无法访问/root
目录(即admin的主目录),因为它在apache或httpd用户的UID下运行。
您应该将virtualenv文件移动到更合适的位置。