首页 > 解决方案 > Apache:同一服务器上的两个域具有不同的端口

问题描述

我是这个东西的新手,所以如果我在做一个愚蠢的问题,请原谅我。我有一个运行在端口 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>

标签: apachevirtualhost

解决方案


发现它:有一些 apache 模块需要激活。刚做了

sudo a2enmod proxy
sudo a2enmod proxy_http

一切都像魅力一样。


推荐阅读