在Apache2上为django部署配置mod_wsgi后出现404错误

时间:2015-04-23 13:58:42

标签: python django apache ubuntu

在Apache2上配置mod_wsgi以进行django部署后,我收到404错误。

环境:Ubuntu Server 14.04.2LTS / Apache 2.4 / django 1.8 / python 3.4

我的apache2.conf如下(我在conf文件末尾添加的内容):

AddHandler cgi-script .cgi .pl .py

WSGIScriptAlias / /var/www/html/youknowmanagementsystem/youknow/wsgi.py
WSGIPythonPath /var/www/html/youknowmanagementsystem

Alias /static/ /var/www/html/youknowmanagementsystem/statics/

<Directory /var/www/html/youknowmanagementsystem/statics>
Require all granted
</Directory>

<Directory /var/www/html/youknowmanagementsystem/youknow>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

我检查了我的apache2错误日志,它显示:

[Thu Apr 23 21:30:52.253785 2015] [mpm_prefork:notice] [pid 5562] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.9 mod_wsgi/3.4 Python/3.4.0 configured -- resuming normal operations
[Thu Apr 23 21:30:52.253836 2015] [core:notice] [pid 5562] AH00094: Command line: '/usr/sbin/apache2'
[Thu Apr 23 21:56:06.006229 2015] [:error] [pid 5566] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Thu Apr 23 21:56:06.006263 2015] [:error] [pid 5566] Traceback (most recent call last):
[Thu Apr 23 21:56:06.006269 2015] [:error] [pid 5566]   File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Thu Apr 23 21:56:06.006648 2015] [:error] [pid 5566]     assert tlock is not None
[Thu Apr 23 21:56:06.006658 2015] [:error] [pid 5566] AssertionError:
[Thu Apr 23 21:56:06.013870 2015] [:error] [pid 5570] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Thu Apr 23 21:56:06.013900 2015] [:error] [pid 5570] Traceback (most recent call last):
[Thu Apr 23 21:56:06.013907 2015] [:error] [pid 5570]   File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Thu Apr 23 21:56:06.014285 2015] [:error] [pid 5570]     assert tlock is not None
[Thu Apr 23 21:56:06.014295 2015] [:error] [pid 5570] AssertionError:
[Thu Apr 23 21:56:06.017918 2015] [:error] [pid 5569] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Thu Apr 23 21:56:06.017945 2015] [:error] [pid 5569] Traceback (most recent call last):
[Thu Apr 23 21:56:06.017952 2015] [:error] [pid 5569]   File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Thu Apr 23 21:56:06.018337 2015] [:error] [pid 5569]     assert tlock is not None
[Thu Apr 23 21:56:06.018346 2015] [:error] [pid 5569] AssertionError:
[Thu Apr 23 21:56:06.021742 2015] [:error] [pid 5586] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Thu Apr 23 21:56:06.021772 2015] [:error] [pid 5586] Traceback (most recent call last):
[Thu Apr 23 21:56:06.021778 2015] [:error] [pid 5586]   File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Thu Apr 23 21:56:06.022339 2015] [:error] [pid 5567] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Thu Apr 23 21:56:06.022357 2015] [:error] [pid 5567] Traceback (most recent call last):
[Thu Apr 23 21:56:06.022362 2015] [:error] [pid 5567]   File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Thu Apr 23 21:56:06.022737 2015] [:error] [pid 5567]     assert tlock is not None
[Thu Apr 23 21:56:06.022748 2015] [:error] [pid 5567] AssertionError:
[Thu Apr 23 21:56:06.024135 2015] [:error] [pid 5568] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Thu Apr 23 21:56:06.024158 2015] [:error] [pid 5568] Traceback (most recent call last):
[Thu Apr 23 21:56:06.024163 2015] [:error] [pid 5568]   File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Thu Apr 23 21:56:06.024535 2015] [:error] [pid 5568]     assert tlock is not None
[Thu Apr 23 21:56:06.024545 2015] [:error] [pid 5568] AssertionError:
[Thu Apr 23 21:56:06.027435 2015] [:error] [pid 5586]     assert tlock is not None
[Thu Apr 23 21:56:06.027462 2015] [:error] [pid 5586] AssertionError:
[Thu Apr 23 21:56:06.085916 2015] [mpm_prefork:notice] [pid 5562] AH00169: caught SIGTERM, shutting down
[Thu Apr 23 21:56:07.053702 2015] [mpm_prefork:notice] [pid 5768] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.9 mod_wsgi/3.4 Python/3.4.0 configured -- resuming normal operations
[Thu Apr 23 21:56:07.053749 2015] [core:notice] [pid 5768] AH00094: Command line: '/usr/sbin/apache2'

如何修复此404错误?如果我能提供更多的详细信息,请告诉我。

1 个答案:

答案 0 :(得分:3)

这解决了我的问题:https://askubuntu.com/questions/569550/assertionerror-using-apache2-and-libapache2-mod-wsgi-py3-on-ubuntu-14-04-python

  

Ubuntu 14.04附带mod_wsgi 3.4。根据   https://code.djangoproject.com/ticket/22948#comment:2我们需要使用   mod_wsgi版本4.2+ for Python 3.4。

     

将mod_wsgi安装到最新版本的最佳方法是获取它   使用pip(可以在virtualenv中)然后将其模块安装到apache   全系统。在我的例子中,我使用/ venv_path中设置的virtualenv。

     

1)删除有问题的包并安装依赖

     

sudo apt-get remove libapache2-mod-wsgi-py3

     

sudo apt-get install apache2-dev

     

2)使用pip

在virtualenv中安装mod_wsgi      

. /venv_path/bin/activate pip install mod_wsgi

     

3)安装到Apache(系统范围)

     

sudo /venv_path/bin/mod_wsgi-express install-module

     

sudo vi /etc/apache2/mods-available/wsgi_express.load /etc/apache2/mods-available/wsgi_express.conf

     

/etc/apache2/mods-available/wsgi_express.load

的内容      

LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi-py34.cpython-34m.so

     

/etc/apache2/mods-available/wsgi_express.conf的内容

     

WSGIPythonHome /venv_path

     

4)启用模块并重启Apache。

     

sudo a2enmod wsgi_express

     

sudo service apache2 restart

     

5)检查/var/log/apache2/error.log

中是否存在错误

所以我们需要像上面的链接一样安装mod_wsgi,它现在可以正常工作。