django 部署在 apache2.4 python3.5(验证) 或 3.x(未验证) 版本出现错误.

首先感谢:@GrahamDumpleton
问题链接: github
一天时间。google了各种问题还是解决不了。百撕不得骑…咳咳
位于/var/log/apache2/error.log 出现

[Mon Jul 25 20:10:41.247841 2016] [wsgi:error] [pid 18106] mod_wsgi (pid=18106): Call to 'site.addsitedir()' failed for '(null)', stopping.
[Mon Jul 25 20:10:41.247874 2016] [wsgi:error] [pid 18106] mod_wsgi (pid=18106): Call to 'site.addsitedir()' failed for '/home/ling/django_project/lib/python3.5/site-packages'.
[Mon Jul 25 20:10:47.198769 2016] [wsgi:error] [pid 18106] mod_wsgi (pid=18106): Call to 'site.addsitedir()' failed for '(null)', stopping.
[Mon Jul 25 20:10:47.198806 2016] [wsgi:error] [pid 18106] mod_wsgi (pid=18106): Call to 'site.addsitedir()' failed for '/home/ling/django_project/lib/python3.5/site-packages'.
[Mon Jul 25 20:10:47.444672 2016] [wsgi:error] [pid 18106] [remote 192.168.1.2:52125] mod_wsgi (pid=18106): Target WSGI script '/home/ling/django_project/project/simple_project/simple_project/wsgi.py' cannot be loaded as Python module.
[Mon Jul 25 20:10:47.444717 2016] [wsgi:error] [pid 18106] [remote 192.168.1.2:52125] mod_wsgi (pid=18106): Exception occurred processing WSGI script '/home/ling/django_project/project/simple_project/simple_project/wsgi.py'.
。。。以下省略。。。因为上面的才是主要问题

The reference to debugging logging code was related to me commenting out logging code in mod_wsgi itself to verify where the issue was coming from, not disabling logging of your own.

Do be aware that any mod_wsgi packages shipped by Debian and Ubuntu are unsupported by Debian or Ubuntu and neither do I support them as they ship out of date ancient versions which are many releases behind. It is basically a myth that in a LTS version of those Linux distributions that they provide support. They don’t, they only do that for certain core packages and not the majority of stuff you might install. If you always use only system provided packages in the belief that they are supported, then the reality is that they aren’t.

As to a workaround, it depends on what paths you are trying to add. If you had something like:

WSGIDaemonProcess [...] python-path=/home/srittau/.virtualenvs/foo/lib/python3.5/site-packages:/home/srittau/foo/bar/pylibs

where one path is that related to a virtual environment, it isn’t the preferred way anyway. For a virtual environment you should use python-home option to specify the root of the virtual environment and not use python-path to specify the site-packages directory. Thus should use:

WSGIDaemonProcess [...] python-home=/home/srittau/.virtualenvs/foo python-path=/home/srittau/foo/bar/pylbs

Thus if the reason for two paths was because of one being the virtual environment, change it to the preferred setup and you should be good. If you are adding multiple directories for other reasons, this will not help and the only other option is to add the paths as part of the WSGI script file

总结

其实出现错误的原因就是不能使用python-path 路径来指定虚拟环境。
而应该使用python-home 路径否则无法正确通过虚拟环境来加载python 应用

附上我的配置作参考(内网下配置- 把192.168.1.2 改为域名):


    ServerName 192.168.1.2
    ServerAdmin [email protected]

    Alias /media/ /home/ling/django_project/project/simple_project/media/
    Alias /static/ /home/ling/django_project/project/simple_project/blog/static/

    
        Require all granted
    

    
        Require all granted
    

    WSGIScriptAlias / /home/ling/django_project/project/simple_project/simple_project/wsgi.py
    WSGIDaemonProcess 192.168.1.2 python-path=/home/ling/django_project/project/simple_project python-home=/home/ling/django_project/lib/python3.5/site-packages
    WSGIProcessGroup 192.168.1.2

    
    
        Require all granted
    
    

你可能感兴趣的:(Django,python3,solution,docker)