简体   繁体   中英

mod_wsgi Target WSGI script cannot be loaded as Python module

Follow flask's doc

http://flask.pocoo.org/docs/0.12/deploying/mod_wsgi/

Apache/2.4.10 flask 0.12.2

Directory Structure:

├── 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 Error:

[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

What should I do?

Permission denied error is usually caused by incorrect owner, group, or file mode setting of the file to be loaded or one of the subdirectories leading to it. Another possible cause is SELinux, but only if it is enabled and in enforcing mode.

Permission denied: '/root/.local/share/virtualenvs/movie_douban-og6kh8C1/bin/activate_this.py'

In this case, almost certainly the Apache process has no access to /root directory (ie admin's home directory), because it is running under UID of apache or httpd user.

You should move your virtualenv files to a more suitable location.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM