与WSGIDaemonProcess的django apacheconfiguration不工作

更新了问题

[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 

这是问题最可能的原因。 您已经在超级用户的主文件夹内创build了一个virtualenv。 但是该文件夹不太可能被apache访问。 默认情况下,用户的主文件夹不能被任何其他用户访问。

Web服务器和WSGI进程将作为非特权用户(通常名为nobodyhttpdapache或类似名称)运行。 虽然你可以通过修改/ root /的权限来解决这个问题,但这是一个很大的问题。 如果它是一个普通用户,那么这样做危险性会小一些,但这样做还不是一个好主意。

最好的解决scheme是将virtualenv放在非特权用户可以访问的位置。 /usr/local/virtualenv是一个很好的位置。

请注意,移动/root/.virtualenvs//usr/local/virtualenv你将不得不重新创build它如下

  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文件以反映新的path。