![如果我尝试在本地主机上使用 ProxyPass 将不同的服务公开为子域,Apache 就会崩溃](https://linux22.com/image/760521/%E5%A6%82%E6%9E%9C%E6%88%91%E5%B0%9D%E8%AF%95%E5%9C%A8%E6%9C%AC%E5%9C%B0%E4%B8%BB%E6%9C%BA%E4%B8%8A%E4%BD%BF%E7%94%A8%20ProxyPass%20%E5%B0%86%E4%B8%8D%E5%90%8C%E7%9A%84%E6%9C%8D%E5%8A%A1%E5%85%AC%E5%BC%80%E4%B8%BA%E5%AD%90%E5%9F%9F%EF%BC%8CApache%20%E5%B0%B1%E4%BC%9A%E5%B4%A9%E6%BA%83.png)
我有多个网站和服务的以下目录结构
/var/www/html/site1
/var/www/html/site2
/var/www/html/site3
/var/www/html/serv1
/var/www/html/serv2
site1
文件夹托管一个网站,site1domain.com
我想公开托管在serv1
和serv2
文件夹中的 Web 应用服务,以便将它们显示为
service1.site1domain.com
service2.site1domain.com
因此我尝试site1domain.conf
通过以下方式在文件中配置虚拟主机
<VirtualHost *:80>
ServerName site1domain.com
ServerAlias www.site1domain.com
DocumentRoot /var/www/html/site1
<Directory /var/www/html/site1>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName service1.site1domain.com
ProxyPreserveHost On
ProxyRequest Off
ProxyPass "/" "localhost/serv1"
ProxyPassReverse "/" "localhost/serv1"
</VirtualHost>
<VirtualHost *:80>
ServerName service2.site1domain.com
ProxyPreserveHost On
ProxyRequest Off
ProxyPass "/" "localhost/serv2"
ProxyPassReverse "/" "localhost/serv2"
</VirtualHost>
但是与服务相关的虚拟主机代码块导致服务器崩溃:退出,错误代码为 1。
有人能帮助我了解如何正确配置它们吗?
答案1
不如这样:
<VirtualHost *:80>
ServerName service1.site1domain.com
DocumentRoot /var/www/html/serv1
</VirtualHost>
<VirtualHost *:80>
ServerName service2.site1domain.com
DocumentRoot /var/www/html/serv2
</VirtualHost>
不需要 mod_proxy。
答案2
错误是由您的ProxyPass
和ProxyPassReverse
指令不包含方案URL 的一部分。正确的语法应该是
ProxyPass "/" "http://localhost/serv1"
ProxyPassReverse "/" "http://localhost/serv1"
然而,安德鲁说得对,反向代理对于此用例来说,这不是必需的,也不是最佳的技术。