带有WSGIDaemonProcess的Django Apache配置不起作用

发布于 2021-01-29 19:14:52

更新的问题

[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>
关注者
0
被浏览
44
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。
    WSGIDaemonProcess   Rent  python-path=/var/www/rent:/root/.virtualenvs/rent/lib/python2.7/site-packages
    

    这是问题的最可能原因。您已经在超级用户的主文件夹中创建了virtualenv。但是该文件夹不太可能被Apache访问。默认情况下,其他任何用户都无法访问用户的主文件夹。

    Web服务器和WSGI过程将运行作为一个非特权用户通常命名为nobodyhttpdapache或者类似的东西。虽然您可以通过更改/ root
    /上的权限来解决此问题,但这不是很大。如果是普通用户,则危险性会降低,但这样做仍然不是一个好主意。

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

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

     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文件以反映新路径。



知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看