简体   繁体   English

Apache:同一台服务器的多个虚拟主机子域

[英]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://gitlab.example.com -> 到 gitlab
https://sonarqube.example.com -> to sonarqube https://sonarqube.example.com -> 到 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...但问题是,如果我 go 到另一个子域(例如:test.example.com),它将重定向到我的 monitoring.example.com 而它应该只重定向到 DocumentRoot ...

How can I segment my virtualHost based on subdomain?如何根据子域对 virtualHost 进行分段?

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! ServerName将使它工作!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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