apache2 error log. Call to 'site.addsitedir()&

2019-07-14 18:27发布

问题:

I would like to connect Python and Apache 2 server in Ubuntu.

So aws have to enter the following code ubuntu server.

pip install Django

sudo apt-get install appache2

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

Then I created the Python project and the app folder as Python venv.

The code for Apache 2 000-default.conf looks like this:

<virtualhost *:80>
WSGIDaemonProcess bot python-path=/home/ubuntu/Django/bot:/home/ubuntu/Django/myvenv/lib/python3.5/site-packages
ServerAdmin webmaster@localhost
WSGIScriptAlias /52.78.108.223 /home/ubuntu/Django/bot/wsgi.py
<Directory /home/ubuntu/Django/bot>
<Files wsgi.py>
        Require all granted
</Files>
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</virtualhost> 

The location is correct. There is no typing miss.

The first argument to 'WSGIScriptAlias ​​/' should be blank, but if you put it in a blank space, you will not see the 'it walked' page when you hit that IP. So I put the external IP of the server. Then it walked well.

Looking at the Apache 2 error log.

[Wed May 02 21:32:28.100569 2018] [wsgi:warn] [pid 22648:tid 140282945054592] mod_wsgi: Compiled for Python/3.5.1+.

[Wed May 02 21:32:28.100633 2018] [wsgi:warn] [pid 22648:tid 140282945054592] mod_wsgi: Runtime using Python/3.5.2.

[Wed May 02 21:32:28.101406 2018] [mpm_event:notice] [pid 22648:tid 140282945054592] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations

[Wed May 02 21:32:28.101426 2018] [core:notice] [pid 22648:tid 140282945054592] AH00094: Command line: '/usr/sbin/apache2'

[Wed May 02 21:32:28.191175 2018] [wsgi:error] [pid 22651:tid 140282945054592] mod_wsgi (pid=22651): Call to 'site.addsitedir()' failed for '(null)', stopping.

[Wed May 02 21:32:28.192041 2018] [wsgi:error] [pid 22651:tid 140282945054592] mod_wsgi (pid=22651): Call to 'site.addsitedir()' failed for '/home/ubuntu/Django/myvenv/lib/python3.5/site-packages'.

[Wed May 02 21:33:21.733277 2018] [mpm_event:notice] [pid 22648:tid 140282945054592] AH00494: SIGHUP received. Attempting to restart

[Wed May 02 21:33:21.787095 2018] [wsgi:warn] [pid 22648:tid 140282945054592] mod_wsgi: Compiled for Python/3.5.1+.

[Wed May 02 21:33:21.787410 2018] [wsgi:warn] [pid 22648:tid 140282945054592] mod_wsgi: Runtime using Python/3.5.2.

[Wed May 02 21:33:21.788397 2018] [mpm_event:notice] [pid 22648:tid 140282945054592] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations

[Wed May 02 21:33:21.788447 2018] [core:notice] [pid 22648:tid 140282945054592] AH00094: Command line: '/usr/sbin/apache2'

[Wed May 02 21:33:21.860854 2018] [wsgi:error] [pid 22781:tid 140282945054592] mod_wsgi (pid=22781): Call to 'site.addsitedir()' failed for '(null)', stopping.

[Wed May 02 21:33:21.860889 2018] [wsgi:error] [pid 22781:tid 140282945054592] mod_wsgi (pid=22781): Call to 'site.addsitedir()' failed for '/home/ubuntu/Django/myvenv/lib/python3.5/site-packages'.

It comes out like this.

I searched the internet. It is said that wsgi version is low.

However, wsgi used by apache2 can only be installed with 'sudo apt-get install libapache2-mod-wsgi-py3'.

The Apache 2 error log shows that wsgi version is 4.3.0.

If you install the latest version of wsgi with 'pip install mod-wsgi', the Apache 2 error log will show 4.3.0.

'Call to' site.addsitedir () 'failed for' (null) ', stopping.' The error log still appears.

How do I resolve this error?

回答1:

Don't use mod_wsgi 4.3.0. It is very old and has an issue from memory with providing multiple directories to python-path. Alternatively use:

WSGIDaemonProcess bot python-home=/home/ubuntu/Django/myvenv python-path=/home/ubuntu/Django/bot

You shouldn't be using site-packages with python-path. That is not the recommended way and hasn't been since mod_wsgi 3.3.

For more details on using virtual environments, see:

  • http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html

If after using pip install mod_wsgi it doesn't show latest mod_wsgi, it is because you didn't disable/uninstall the system mod_wsgi package. You would need to have manually configured Apache to load the newer mod_wsgi as well, by running mod_wsgi-express module-config and taking the output and add it to Apache configuration.