Target WSGI script '/var/www/backend/backend/w

2019-07-01 10:28发布

I'm deploying a Django web app on ubuntu server. Configuration are set. But, somehow, it show an 500 Internal Server Error. I checked the apache error log and found the following error entry :

[Tue Mar 26 08:50:56.540300 2019] [wsgi:error] [pid 18832] [remote 27.61.32.236:42365] mod_wsgi (pid=18832): Target WSGI script '/var/www/backend/backend/wsgi.py' cannot be loaded as Python module.
[Tue Mar 26 08:50:56.540376 2019] [wsgi:error] [pid 18832] [remote 27.61.32.236:42365] mod_wsgi (pid=18832): Exception occurred processing WSGI script '/var/www/backend/backend/wsgi.py'.
[Tue Mar 26 08:50:56.540498 2019] [wsgi:error] [pid 18832] [remote 27.61.32.236:42365] Traceback (most recent call last):
[Tue Mar 26 08:50:56.540542 2019] [wsgi:error] [pid 18832] [remote 27.61.32.236:42365]   File "/var/www/backend/backend/wsgi.py", line 12, in <module>
[Tue Mar 26 08:50:56.540553 2019] [wsgi:error] [pid 18832] [remote 27.61.32.236:42365]     from django.core.wsgi import get_wsgi_application
[Tue Mar 26 08:50:56.540584 2019] [wsgi:error] [pid 18832] [remote 27.61.32.236:42365] ImportError: No module named 'django'

I have tried the solutions for the same error found on stackoverflow. Is there anything I'm still missing on these configurations ?

Apache Configuration

Listen 8000
<VirtualHost *:8000>
WSGIDaemonProcess backendapp python-home=/var/www/backend/venv python-path=/var/www/backend
WSGIProcessGroup backendapp
WSGIPassAuthorization On
WSGIScriptAlias / /var/www/backend/backend/wsgi.py
ErrorLog /var/www/backend/error.log
CustomLog /var/www/backend/access.log combined
</VirtualHost>

wsgi.py

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings")

application = get_wsgi_application()

using python 3.6 and mod_wsgi is enabled on server.

1条回答
Viruses.
2楼-- · 2019-07-01 10:56

The problem was wsgi python version mismatch. I was using python 3, so:

$ sudo apt-get remove libapache2-mod-python libapache2-mod-wsgi
$ sudo apt-get install libapache2-mod-wsgi-py3
查看更多
登录 后发表回答