Apache mod_wsgi error with django in virtualenv

I can not find a good answer to this question. Who needs to own virtualenv when running it as WSGIDaemon? I assume on my OS (Ubuntu 16) www-data, but I want to be sure. Trying some new things to get this work to work from the answer from this post ...

Django apache configuration with WSGIDaemonProcess not working

Should the django project, virtualenv folder or other belong to the apache group? What owners must be in place to serve the django project without specifying a port? Why am I getting the following?

Root problem:

 Call to 'site.addsitedir()' failed for '(null)'

When I start apache, I get this error. I followed several different guides, including: http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html and also https://docs.djangoproject.com/en/1.10/ howto / deployment / wsgi / modwsgi / but achieved zero success.

My virtual environment path /usr/local/virtualenvs/servicesite

My path to the django project /home/addohm/projects/rtservice/servicesite is where manage.py is located, which leaves /home/addohm/projects/rtservice/servicesite/servicesitemy wsgi.py as the location.

wsgi.py:

SERVICESITE = ['/usr/local/virtualenvs/servicesite/lib/python3.5/site-packages']

import os
import sys
import site

prev_sys_path = list(sys.path)

for directory in SERVICESITE
        site.addsitedir(directory)

new_sys_path = []
for item in list(sys.path):
        if item not in prev_sys_path:
                new_sys_path.append(item)
                sys.path.remove(item)
sys.path[:0] = new_sys_path

"""  **Doesn't seem to work, throwing error in apache logs**
site.addsitedir('/usr/local/virtualenvs/servicesite/lib/python3.5/site-packages')
"""

from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "servicesite.settings")
application = get_wsgi_application()
DJANGO_PATH =  os.path.join(os.path.abspath(os.path.dirname(__file__)), '..')
sys.path.append(DJANGO_PATH)

apache2.conf

[...]

WSGIDaemonProcess servicesite python-path=/home/addohm/projects/rtservice/servicesite:/usr/local/virtualenvs/servicesite/lib/python3.5/site-packages
WSGIProcessGroup servicesite
WSGIScriptAlias / /home/addohm/projects/rtservice/servicesite/servicesite/wsgi.py

Alias /static/ /home/addohm/projects/rtservice/servicesite/static/
<Directory /home/addohm/projects/rtservice/servicesite/static/>
        Require all granted
</Directory>

<Directory /home/addohm/projects/rtservice/servicesite/servicesite>
        <Files wsgy.py>
                Require all granted
        </Files>
</Directory>

[...]

+4
source share
1 answer

wsgi.py, Django . :

import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "servicesite.settings")
application = get_wsgi_application()

Apache :

WSGIDaemonProcess service site python-home=/usr/local/virtualenvs/servicesite \
    python-path=/home/addohm/projects/rtservice/servicesite
WSGIProcessGroup servicesite
WSGIScriptAlias / /home/addohm/projects/rtservice/servicesite/servicesite/wsgi.py

Alias /static/ /home/addohm/projects/rtservice/servicesite/static/
<Directory /home/addohm/projects/rtservice/servicesite/static/>
        Require all granted
</Directory>

<Directory /home/addohm/projects/rtservice/servicesite/servicesite>
        <Files wsgy.py>
                Require all granted
        </Files>
</Directory>

, python-home , sys.prefix . python-path site-packages. python-home , , , - .

.

-, mod_wsgi / Python, .

-, Python Python, mod_wsgi. mod_wsgi Python, Python / /usr/local.

-, , Apache , / Python, . , , - .

-, mod_wsgi , Apache, Apache - , , wsgi.py .

, :

+8

Source: https://habr.com/ru/post/1657225/


All Articles