我发现这个帖子并更新了我的配置。
我在 Apache 上有这个反向代理配置。
<VirtualHost *:80>
ServerName a123.com
ServerAlias www.a123.com
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/ [R,L]
</VirtualHost>
<VirtualHost *:443>
ProxyPreserveHost On
ProxyPass "/test2/" "http://localhost:48630"
ProxyPassReverse "/test2/" "http://localhost:48630"
ProxyPass "/" "http://localhost:5000/"
ProxyPassReverse "/" "http://localhost:5000/"
ErrorLog /var/log/httpd/a123-error.log
CustomLog /var/log/httpd/a123-access.log common
SSLEngine on
SSLCertificateFile /etc/ssl/certs/a123.com.crt
SSLCertificateKeyFile /etc/ssl/private/a123.com.key
</VirtualHost>
应如何更改此配置才能同时访问 www.a123.com 和 test2.a123.com 子域?
我现在只能用这个配置访问 www.a123.com 或 www.a123.com/test2/ 吗?
答案1
您可以为每个域编写两个 VirtualHost,并将它们传递到不同的位置。
编辑:2 个虚拟主机且无 SSL
编辑:DNS 配置中必须允许所有子域名*
<VirtualHost *:80>
ServerName a123.com
ServerAlias www.a123.com
ProxyPreserveHost On
ProxyPass "/" "http://localhost:5000/"
ProxyPassReverse "/" "http://localhost:5000/"
ErrorLog /var/log/httpd/a123-error.log
CustomLog /var/log/httpd/a123-access.log common
</VirtualHost>
<VirtualHost *:80>
ServerName test2.a123.com
ServerAlias www.test2.a123.com
ProxyPreserveHost On
ProxyPass "/" "http://localhost:48630/"
ProxyPassReverse "/" "http://localhost:48630/"
ErrorLog /var/log/httpd/test-a123-error.log
CustomLog /var/log/httpd/test-a123-access.log common
</VirtualHost>
答案2
这是一个虚拟主机配置。它将应用于使用与 ServerName 和 ServerAlias 指令匹配的域对您的服务器的所有调用。您可以拥有更多别名。
ServerAlias www.a123.com test2.a123.com
或者如果你想要所有子域名:
ServerAlias *.a123.com