JordanChina
JordanChina

Reputation: 345

404 error after configured mod_wsgi on Apache2 for django deployment

I got 404 error after configured mod_wsgi on Apache2 for django deployment.

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

My apache2.conf is as following(contents I added at the end of the conf file):

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>

And I checked my apache2 error log, it shows:

[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'

How can I fix this 404 error? Please let me know if I can provide any more detials.

Upvotes: 0

Views: 2151

Answers (1)

JordanChina
JordanChina

Reputation: 345

this solved my question: https://askubuntu.com/questions/569550/assertionerror-using-apache2-and-libapache2-mod-wsgi-py3-on-ubuntu-14-04-python

Ubuntu 14.04 comes with mod_wsgi 3.4. According to https://code.djangoproject.com/ticket/22948#comment:2 we need to use mod_wsgi version 4.2+ for Python 3.4.

The best way to install mod_wsgi to the latest version is to get it with pip (can be in virtualenv) and then install its module to apache system-wide. In my case I use virtualenv set in /venv_path.

1) Remove problematic package and install dependency

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

sudo apt-get install apache2-dev

2) Install mod_wsgi in virtualenv with pip

. /venv_path/bin/activate pip install mod_wsgi

3) Install into Apache (system-wide)

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

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

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

Content of /etc/apache2/mods-available/wsgi_express.conf

WSGIPythonHome /venv_path

4) Enable the module and restart Apache.

sudo a2enmod wsgi_express

sudo service apache2 restart

5) Check that there are no errors in /var/log/apache2/error.log

so we need to install mod_wsgi as in above link, and it works now.

Upvotes: 4

Related Questions