Apache2 Reverse Proxy sending Http and Https traffic from a subdomain into the main domain

I am trying to use Apache2’s reverse proxy, and using different subdomains to configure different services. (example.com for an index page, gitea.example.com for a gitea instance, nc.example.com for a different service).

However, the output that I am getting from this is both websites are being directed into example.com, and not the one for their domain. Have I misconfigured something?

gitea.example.com.conf:

<VirtualHost *:80>
    ServerName gitea.example.com
    ProxyPreserveHost On
    ProxyRequests Off
    ProxyPass / http://localhost:2080/
    ProxyPassReverse / http://localhost:2080/
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName gitea.example.com
    ProxyPreserveHost On
    ProxyRequests Off
    ProxyPass / https://localhost:2443/
    ProxyPassReverse / https://localhost:2443/

    SSLProxyEngine on
    
    SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

000-default.conf:

<VirtualHost *:80>
    ServerName example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

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

</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName example.com
    DocumentRoot /var/www/html


    SSLProxyEngine on
    SSLEngine on    
    SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

I had originally tried having them all in one file, however I then got an error about a non-consistent ServerName, and that it would fail to load because of this

Leave a Comment