Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
209 views
in Technique[技术] by (71.8m points)

python - django apache configuration with WSGIDaemonProcess not working

Updated Question

[Mon Jul 18 09:20:10.517873 2016] [:error] [pid 30316:tid 139756302964480] [remote 122.164.94.99:48261] Traceback (most recent call last):
[Mon Jul 18 09:20:10.518005 2016] [:error] [pid 30316:tid 139756302964480] [remote 122.164.94.99:48261]   File "/var/www/rent/Rent/wsgi.py", line 20, in <module>
[Mon Jul 18 09:20:10.518141 2016] [:error] [pid 30316:tid 139756302964480] [remote 122.164.94.99:48261]     from django.core.wsgi import get_wsgi_application
[Mon Jul 18 09:20:10.518236 2016] [:error] [pid 30316:tid 139756302964480] [remote 122.164.94.99:48261] ImportError: No module named django.core.wsgi

My virtualhost

<VirtualHost *:80>
    ServerName  ip_address
    ServerAdmin webmaster@localhost

    Alias /static/  /var/www/rent/static/

    Alias /media/  /var/www/rent/media/

    WSGIScriptAlias /   /var/www/rent/Rent/wsgi.py

    WSGIDaemonProcess   Rent  python-path=/var/www/rent:/root/.virtualenvs/rent/lib/python2.7/site-packages

    WSGIProcessGroup    Rent

    <Directory /var/www/rent/static>
        Options -Indexes
        Order deny,allow
        Allow from all
    </Directory>

    <Directory /var/www/rent/media>
        Options -Indexes
        Order deny,allow
        Allow from all
    </Directory>

    LogLevel warn

    ErrorLog    ${APACHE_LOG_DIR}/error.log
    CustomLog   ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
WSGIDaemonProcess   Rent  python-path=/var/www/rent:/root/.virtualenvs/rent/lib/python2.7/site-packages

This is the most likely cause of the problem. You have created a virtualenv inside the super user's home folder. But that folder is unlikely to be accessible to apache. A user's home folder is not accessible to any other user by default.

The web server and the WSGI process will be running as a non privileged user typically named nobody, httpd, apache or something similar. While you can fix this problem by changing the permissions on /root/ that's a big no no. It would be less dangerous if it was an ordinary user but still not a good idea to do this.

The best solution is to put the virtualenv in a location accessible by the unprivileged user. /usr/local/virtualenv is a good location.

Please note that moving /root/.virtualenvs/ to /usr/local/virtualenv you will have to recreate it as follows

 source /root/.virtualenvs/rent/bin/activate
 pip freeze > /tmp/requirements.txt
 cd /usr/local/
 virtualenv virtualenv
 source virtualenv/bin/activate
 pip install -r /tmp/requirements.txt

then edit the httpd.conf file to reflect the new path.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...