Apache:同一服务器上的两个域具有不同的端口

时间:2021-07-25 18:09:09

标签: apache virtualhost

我是这方面的新手,所以如果我问了一个愚蠢的问题,请原谅我。我有一个在端口 80 上运行的 vue 应用程序通过 SSL 工作得很好(比如 www.domain.com 和 domain.com)。

现在我需要我的 springboot 应用程序,它运行在端口 8443 上也可以通过安全连接访问(比如在 api.domain.com 上),但我不太明白我做错了什么...... 如果我不包括第二个虚拟主机,我可以访问 api,但只使用 http...此外,当我输入 api.domain.com 时,它也会进入 domain.com 起始页。当我包含第二个虚拟主机时,我什至无法访问 domain.com。

<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

ServerName www.domain.com
Include /etc/letsencrypt/options-ssl-apache.conf
ServerAlias domain.com
ProxyPreserveHost On
SSLCertificateFile /etc/letsencrypt/live/domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/domain.com/privkey.pem
</VirtualHost>
<VirtualHost *:443>
    ServerAdmin webmaster@localhost
    ServerName api.domain.com

    Include /etc/letsencrypt/options-ssl-apache.conf
    ServerAlias api.domain.com
    SSLCertificateFile /etc/letsencrypt/live/domain.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/domain.com/privkey.pem
    ProxyPreserveHost On
        ProxyPass / http://127.0.0.1:8443/
        ProxyPassReverse / http://127.0.0.1:8443/
</VirtualHost>
</IfModule>

1 个答案:

答案 0 :(得分:0)

发现:有一些apache模块需要激活。刚刚用

sudo a2enmod proxy
sudo a2enmod proxy_http

一切都像魅力一样。