简体   繁体   中英

Apache: Multiple virtual host subdomain for the same server

I would like to redirect all my apps to their urls:
for example:
https://gitlab.example.com -> to gitlab
https://sonarqube.example.com -> to sonarqube

Here is my actual config:

<IfModule mod_ssl.c>
<VirtualHost monitoring.example.com:443>
    ServerName monitoring.example.com

    # Monitoring
    ProxyPass / http://localhost:9089/
    ProxyPassReverse / http://localhost:9089/

SSLEngine on
SSLCertificateFile      /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile   /etc/letsencrypt/live/example.com/privkey.pem
</VirtualHost>

<VirtualHost sonarqube.example.com:443>
    ServerName sonarqube.example.com

    # Sonarqube
    ProxyPass / http://localhost:90000/
    ProxyPassReverse / http://localhost:90000/

SSLEngine on
SSLCertificateFile      /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile   /etc/letsencrypt/live/example.com/privkey.pem
</VirtualHost>

<VirtualHost *:443>
        ServerName example.com

        DocumentRoot /var/www/html

        ErrorLog /var/log/apache2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined

        SSLEngine on
        SSLCertificateFile      /etc/letsencrypt/live/example.com/fullchain.pem
        SSLCertificateKeyFile   /etc/letsencrypt/live/example.com/privkey.pem
</VirtualHost>
</IfModule>

But there problem is that if I go to another subdomain (ex: test.example.com) it will redirect to my monitoring.example.com whereas it should only redirect to DocumentRoot...

How can I segment my virtualHost based on subdomain?

Finally it seems that I don't have to put

<VirtualHost monitoring.example.com:443>

but I need to put

<VirtualHost *:443>

The ServerName will make it works!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM