Problems setting up two Django sites in the same servername with two virtualhost files

23 views
Skip to first unread message

Dostowiesky Ugel

unread,
Feb 17, 2021, 2:24:56鈥疨M2/17/21
to modwsgi
Good morning, I'm trying to enable two Django Websites in my server but I can not make it work, I have only one subdomain and both sites should work from it.

The problem is that when I activate site's 1 virtualhost I can see it perfectly, but when I activate the site's 2 virtualhost I can only see site 2, and then when I try to see site 1 it shows the apache2 default page.

Below is my config

My site 1 is the root.

聽聽聽聽聽聽聽 Site 1 VirtualHost
<IfModule mod_ssl.c>
聽聽聽 <VirtualHost *:443>
聽聽聽聽聽聽聽 ServerAdmin webmaster@localhost
聽聽聽聽聽聽聽 #DocumentRoot /var/www/html


聽聽聽聽聽聽聽 ErrorLog ${APACHE_LOG_DIR}/error.log
聽聽聽聽聽聽聽 CustomLog ${APACHE_LOG_DIR}/access.log combined

聽聽聽聽聽聽聽 #聽聽 SSL Engine Switch:
聽聽聽聽聽聽聽 #聽聽 Enable/Disable SSL for this virtual host.
聽聽聽聽聽聽聽 SSLEngine on

聽聽聽聽聽聽聽 #聽聽 A self-signed (snakeoil) certificate can be created by installing
聽聽聽聽聽聽聽 #聽聽 the ssl-cert package. See
聽聽聽聽聽聽聽 #聽聽 /usr/share/doc/apache2/README.Debian.gz for more info.
聽聽聽聽聽聽聽 #聽聽 If both key and certificate are stored in the same file, only the
聽聽聽聽聽聽聽 #聽聽 SSLCertificateFile directive is needed.
聽聽聽聽聽聽聽 SSLCertificateFile /etc/letsencrypt/route to my certificate
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 SSLCertificateKeyFile /etc/letsencrypt/route to my certificate

聽聽聽聽聽聽
聽聽聽聽聽聽聽 #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
聽聽聽聽聽聽聽 <FilesMatch "\.(cgi|shtml|phtml|php)$">
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 SSLOptions +StdEnvVars
聽聽聽聽聽聽聽 </FilesMatch>
聽聽聽聽聽聽聽 <Directory /usr/lib/cgi-bin>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 SSLOptions +StdEnvVars
聽聽聽聽聽聽聽 </Directory>

聽聽聽聽聽聽聽 #Prestashop
聽聽聽聽聽聽聽 alias /prestashop /var/www/html/prestashop
聽聽聽聽聽聽聽 <Directory /var/www/html/prestashop>
聽聽聽聽聽聽聽聽聽聽聽 Require all granted
聽聽聽聽聽聽聽 </Directory>
聽聽聽聽聽聽

聽聽聽聽聽聽聽 #My website

聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 alias /static /route to my static folder/static
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <Directory /route to my static folder/static>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 Require all granted
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 </Directory>

聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <Directory /route to my wsgi.py folder>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <Files wsgi.py>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 Require all granted
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 </Files>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 </Directory>

聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 WSGIDaemonProcess site python-path=/pathtomanage.pyfolder python-home=/pathtothevenvfolder
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 WSGIProcessGroup site
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 WSGIScriptAlias / /home/dostow/dostowsite/webcode/webcode/wsgi.py application-group=%{GLOBAL}
聽聽聽 </VirtualHost>
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 Site 2 VirtualHost
<IfModule mod_ssl.c>
聽聽聽 <VirtualHost *:443>
聽聽聽聽聽聽聽 ServerAdmin webmaster@localhost

聽聽聽聽聽聽聽 ErrorLog ${APACHE_LOG_DIR}/error.log
聽聽聽聽聽聽聽 CustomLog ${APACHE_LOG_DIR}/access.log combined

聽聽聽聽聽聽聽 #聽聽 SSL Engine Switch:
聽聽聽聽聽聽聽 #聽聽 Enable/Disable SSL for this virtual host.
聽聽聽聽聽聽聽 SSLEngine on

聽聽聽聽聽聽聽 #聽聽 A self-signed (snakeoil) certificate can be created by installing
聽聽聽聽聽聽聽 #聽聽 the ssl-cert package. See
聽聽聽聽聽聽聽 #聽聽 /usr/share/doc/apache2/README.Debian.gz for more info.
聽聽聽聽聽聽聽 #聽聽 If both key and certificate are stored in the same file, only the
聽聽聽聽聽聽聽 #聽聽 SSLCertificateFile directive is needed.
聽聽聽聽聽聽聽 SSLCertificateFile /etc/letsencrypt/live/route to my certificate
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 SSLCertificateKeyFile /etc/letsencrypt/live/route to my certificate

聽聽聽聽聽聽聽 #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
聽聽聽聽聽聽聽 <FilesMatch "\.(cgi|shtml|phtml|php)$">
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 SSLOptions +StdEnvVars
聽聽聽聽聽聽聽 </FilesMatch>
聽聽聽聽聽聽聽 <Directory /usr/lib/cgi-bin>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 SSLOptions +StdEnvVars
聽聽聽聽聽聽聽 </Directory>

聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽 #AAVVMARESME
聽聽聽聽聽聽聽 alias /site2/static /route to my static folder/static
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <Directory /route to my static folder/static>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 Require all granted
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 </Directory>

聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <Directory /route to my wsgi.py folder>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <Files wsgi.py>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 Require all granted
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 </Files>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 </Directory>

聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 WSGIDaemonProcess site2 python-path=/pathtomanage.pyfolder python-home=/pathtothevenvfolder
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 WSGIProcessGroup site2
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 WSGIScriptAlias /site2 /route to my wsgi.py folder/wsgi.py application-group=%{GLOBAL}
聽聽聽 </VirtualHost>
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

i would appreciate your help!!

Graham Dumpleton

unread,
Feb 17, 2021, 2:27:46鈥疨M2/17/21
to mod...@googlegroups.com
You aren't specifying ServerName directive in each VirtualHost for a start so Apache can't tell the VirtualHost's apart by host name.

Was that only in the email that you left them out?

See:


for general advice on multiple sites being mixed up when using Django.

Just note the post is old and using process-group and application-group options to WSGIScriptAlias is now the preferred.

Graham

--
You received this message because you are subscribed to the Google Groups "modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/modwsgi/724c9d9d-249e-4e12-a426-2c24d525289cn%40googlegroups.com.

Dostowiesky Ugel

unread,
Feb 17, 2021, 3:00:43鈥疨M2/17/21
to modwsgi
Good evening! thanks for the quick answer!

I put the ServerName in the apache2.conf file in /etc/apache2/apache2.conf

Below the code:

# Global configuration
#
ServerName https://apps.dostow.tech

If I have to put the ServerName in each VirtualHost can it be the same one in both files?

I have only one subdomain "apps.dostow.tech" in this case so I can not use another.

Thanks again for your help!!

Graham Dumpleton

unread,
Feb 17, 2021, 3:03:40鈥疨M2/17/21
to mod...@googlegroups.com

On 18 Feb 2021, at 7:00 am, Dostowiesky Ugel <wladim...@gmail.com> wrote:

Good evening! thanks for the quick answer!

I put the ServerName in the apache2.conf file in /etc/apache2/apache2.conf

Below the code:

# Global configuration
#
ServerNamehttps://apps.dostow.tech

If I have to put the ServerName in each VirtualHost can it be the same one in both files?

No it can't. Apache would always use the first VirtualHost found if you did.

You will have to merge the two VirtualHost definitions. Just ensure the WSGIScriptAlias for the sub path appears before that for the root of the site so it takes precedence. Ensure you use process-group option on WSGIScriptAlias instead of WSGIProcessGroup directive. Doing it this way is mentioned in the post I linked.

Dostowiesky Ugel

unread,
Feb 17, 2021, 3:08:53鈥疨M2/17/21
to modwsgi
Ok! Understood, I will put both in the same VirtualHost file and add process-group option on WSGIScriptAlias, I will let you know the result, thank you!!

Graham Dumpleton

unread,
Feb 17, 2021, 3:13:51鈥疨M2/17/21
to mod...@googlegroups.com
Just to be clear. It isn't adding the two separate VirtualHost's to one file, but merging the contents of the VirtualHost's so you only have one. Thus:


<VirtualHost *:443>
ServerName apps.dostow.tech

WSGIDaemonProcess project-2
WSGIScriptAlias /suburl /some/path/project-2/wsgi.py聽process-group=project-2 application-group=%{GLOBAL}

WSGIDaemonProcess project-1
WSGIScriptAlias / /some/path/project-1/wsgi.py聽process-group=project-1 application-group=%{GLOBAL}

...

</VirtualHost>

Dostowiesky Ugel

unread,
Feb 17, 2021, 3:14:59鈥疨M2/17/21
to modwsgi
Perfect!! Yahoooo thank you so much!! It works now :-D Just adding the process-group option.
Thank you again!

Dostowiesky Ugel

unread,
Feb 17, 2021, 3:18:04鈥疨M2/17/21
to modwsgi
Yes I did it exactly this way you said, merging the contents of the VirtualHost's and now it works perfect!

Thanks for your support!
Reply all
Reply to author
Forward
0 new messages