2015-04-23 79 views
0

在Apache2上为Django部署配置mod_wsgi后,我得到了404错误。Django部署Apache2上配置mod_wsgi后出现404错误

ENV:Ubuntu服务器14.04.2LTS/Apache的2.4/1.8的Django/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错误?请让我知道,如果我可以提供更多detials。

+0

您没有404错误。 –

+0

@DanielRoseman你是指这个细节?未找到 在此服务器上未找到请求的URL /。 Apache/2.4.7(Ubuntu)Server at 127.0.0.1 Port 8002 – JordanChina

回答

2

这个解决我的问题: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我们需要为Python 3.4使用 mod_wsgi版本4.2+。

将mod_wsgi安装到最新版本的最好方法是使用pip(可以在virtualenv中)获得 ,然后将其模块安装到系统范围内的Apache 。在我的情况下,我使用/ venv_path中的virtualenv设置。

1)取下有问题的包和安装依赖性

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

sudo apt-get install apache2-dev

2)中的virtualenv与PIP

. /venv_path/bin/activate pip install mod_wsgi

3安装mod_wsgi的)安装到的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

内容/等/ apache2的/ MODS的可用/ wsgi_express.conf

WSGIPythonHome /venv_path

4)启用模块并重启Apache。

sudo a2enmod wsgi_express

sudo service apache2 restart

5)检查是否有在/ var没有错误/日志/的Apache2 /错误。日志

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

相关问题