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 PM2/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 PM2/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 PM2/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 PM2/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
#
ServerName https://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 PM2/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 PM2/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 PM2/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 PM2/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