更新的问题
[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
我的虚拟主机
<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>
WSGIDaemonProcess Rent python-path=/var/www/rent:/root/.virtualenvs/rent/lib/python2.7/site-packages
这是问题的最可能原因。您已经在超级用户的主文件夹中创建了virtualenv。但是该文件夹不太可能被Apache访问。默认情况下,其他任何用户都无法访问用户的主文件夹。
Web服务器和WSGI过程将运行作为一个非特权用户通常命名为nobody,httpd,apache或者类似的东西。虽然您可以通过更改/ root /上的权限来解决此问题,但这不是很大。如果是普通用户,则危险性会降低,但这样做仍然不是一个好主意。
nobody
httpd
apache
最好的解决方案是将virtualenv放置在非特权用户可以访问的位置。 /usr/local/virtualenv是一个好的位置。
/usr/local/virtualenv
请注意,移动/root/.virtualenvs/到/usr/local/virtualenv你将不得不重新创建如下
/root/.virtualenvs/
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
然后编辑httpd.conf文件以反映新路径。
httpd.conf