我有多个网站和服务的以下目录结构
/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"
然而,安德鲁说得对,反向代理对于此用例来说,这不是必需的,也不是最佳的技术。