I have been pulling my hair out with this and I dont know what else I should do. For context, I am trying to host 2 django websites on the same Apache2 server. I am able to setup 1 website with ease but whenever I try to add a second one everything breaks. At the momento both webs are located in in /home/my_usr dir. So we would have /home/my_usr/web1 and /home/my_usr/web2.
My web1-web2.conf file looks like:
WSGIDaemonProcess web1 python-home=/home/my_usr/web1/env python-path=/home/my_usr/web1
WSGIProcessGroup web1
WSGIDaemonProcess web2 python-home=/home/my_usr/web2/env python-path=/home/my_usr/web2
WSGIProcessGroup web2
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that the server uses to
# identify itself. This is used when creating redirection URLs. In the context of virtual hosts, the
# ServerName specifies what hostname must appear in the request's Host: header to match this virtual
# host. For the default virtual host (this file) this value is not decisive as it is used as a last
# resort host regardless. However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg. It is also possible to configure the loglevel for particular modules,
# e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are enabled or disabled at a global level,
# it is possible to include a line for only one particular virtual host. For example the following
# line enables the CGI configuration for this host only after it has been globally disabled with
# "a2disconf".
#Include conf-available/serve-cgi-bin.conf
Alias /web1/static /home/my_usr/web1/static
<Directory /home/my_usr/web1/static>
Require all granted
</Directory>
Alias /media /home/my_usr/web1/media
<Directory /home/my_usr/web1/media>
Require all granted
</Directory>
<Directory /home/my_usr/web1/web1>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias /web1 /home/my_usr/web1/web1/wsgi.py
Alias /web2/static/ /home/my_usr/web2/static
<Directory /home/my_usr/web2/static>
Require all granted
</Directory>
Alias /media /home/my_usr/web2/media
<Directory /home/my_usr/web2/media>
Require all granted
</Directory>
<Directory /home/my_usr/web2//web>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias /web2 /home/my_usr/web2/web2/wsgi.py
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
With this conf file, and right after I execute sudo service apache2 restart
, if I go onto host/web1 web1 works perfeclty fine but if I want to access to host/web2 I get an error message and this error in the error.log file:
[Fri Jul 02 11:45:45.210666 2021] [mpm_prefork:notice] [pid 29254] AH00163: Apache/2.4.46 (Debian) mod_wsgi/4.6.5 Python/3.7 configured -- resuming normal operations
[Fri Jul 02 11:45:45.210780 2021] [core:notice] [pid 29254] AH00094: Command line: '/usr/sbin/apache2'
[Fri Jul 02 11:46:13.416556 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] mod_wsgi (pid=29256): Failed to exec Python script file '/home/my_usr/web2/web2/wsgi.py'.
[Fri Jul 02 11:46:13.416650 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] mod_wsgi (pid=29256): Exception occurred processing WSGI script '/home/my_usr/web2/web2/wsgi.py'.
[Fri Jul 02 11:46:13.417397 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] Traceback (most recent call last):
[Fri Jul 02 11:46:13.417464 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "/home/my_usr/web2/web2/wsgi.py", line 24, in <module>
[Fri Jul 02 11:46:13.417517 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] application = get_wsgi_application()
[Fri Jul 02 11:46:13.417526 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "/home/my_usr/web2/env/lib/python3.7/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Fri Jul 02 11:46:13.417530 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] django.setup(set_prefix=False)
[Fri Jul 02 11:46:13.417546 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "/home/my_usr/web2/env/lib/python3.7/site-packages/django/__init__.py", line 19, in setup
[Fri Jul 02 11:46:13.417550 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Fri Jul 02 11:46:13.417555 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "/home/my_usr/web2/env/lib/python3.7/site-packages/django/conf/__init__.py", line 82, in __getattr__
[Fri Jul 02 11:46:13.417559 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] self._setup(name)
[Fri Jul 02 11:46:13.417564 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "/home/my_usr/web2/env/lib/python3.7/site-packages/django/conf/__init__.py", line 69, in _setup
[Fri Jul 02 11:46:13.417567 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] self._wrapped = Settings(settings_module)
[Fri Jul 02 11:46:13.417572 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "/home/my_usr/web2/env/lib/python3.7/site-packages/django/conf/__init__.py", line 170, in __init__
[Fri Jul 02 11:46:13.417575 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] mod = importlib.import_module(self.SETTINGS_MODULE)
[Fri Jul 02 11:46:13.417580 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
[Fri Jul 02 11:46:13.417583 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] return _bootstrap._gcd_import(name[level:], package, level)
[Fri Jul 02 11:46:13.417588 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
[Fri Jul 02 11:46:13.417593 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "<frozen importlib._bootstrap>", line 983, in _find_and_load
[Fri Jul 02 11:46:13.417598 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
[Fri Jul 02 11:46:13.417603 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[Fri Jul 02 11:46:13.417608 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
[Fri Jul 02 11:46:13.417612 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "<frozen importlib._bootstrap>", line 983, in _find_and_load
[Fri Jul 02 11:46:13.417617 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
[Fri Jul 02 11:46:13.417634 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] ModuleNotFoundError: No module named 'web1'
Whereas, if I execute sudo service apache2 restart
and directly go onto host/web2 now web2 works perfectly fine but if after that I try to go onto host/web1 it shows web2.
So basically if I restart apache2 service then go to host/web1 and after that host/web2 I get a message error and the logs posted.
If I restart apache2 service then go to host/web2 and after that host/web1 I get web2 contents even though the url is host/web2
Any clue what could be going?
Thanks in advance