我正在运行 Apache,并且在 apache 中有一个.conf
文件,site-enabled
如下所示。
<Virtualhost blog.example.com:80>
ServerName blog.example.com
ServerAdmin [email protected]
ProxyRequests Off
ProxyPass /phpmyadmin !
ProxyPass / http://localhost:2368/
ProxyPassReverse / http://localhost:2368/
</Virtualhost>
如您所见,我只希望blog.example.com
ProxyPass 命令处理命中。但是,它实际上影响了所有其他域example.com
,other.example.com
.
我在这里错过了什么吗?
如果这就是 ProxyPass 的工作方式,有没有办法告诉它在检测到物理文件和目录时忽略物理文件和目录?
启用其他站点(只有一个站点在 ruby 下运行,其余的遵循第一种形式):
<VirtualHost other.example.com:80>
ServerName other.example.com
ServerAdmin [email protected]
DocumentRoot /var/www/html/other
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<Virtualhost other2.example.com:80>
ServerName other2.example.com
ServerAdmin [email protected]
DocumentRoot /var/www/html/rails/other2/public
<Directory /var/www/html/rails/other2/public>
AllowOverride all
Options -MultiViews
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
PassengerUser www-data
PassengerAppEnv production
PassengerRuby /usr/local/rvm/gems/ruby-2.1.2/wrappers/ruby
</Virtualhost>
在定义中使用 FQDN不是最佳实践
VirtualHost
,它可能会导致诸如此类的意外问题。我猜一些主机名在服务器内解析为与请求发送到的 IP 地址不同的 IP 地址。这可能会阻止 Apache 匹配正确的虚拟主机。因此,
VirtualHost
可以将所有虚拟主机的定义更改如下,这样我们就可以确保 Apache 匹配基于正确名称的虚拟主机。需要注意的另一点是,如果您希望请求
example.com
由默认主机以外的虚拟主机提供服务,则需要一个ServerAlias mydomain
指令。这个页面有更多关于基于名称的虚拟主机如何工作的细节——http: //httpd.apache.org/docs/current/vhosts/name-based.html
像这样调整你的配置。请注意我为
VirtualHost
指令设置的通配符。最好只使用通配符 (*
)VirtualHost
指令。此外,我设置了一个ServerAlias
以及间隔和格式化配置以便于阅读,这在调试此类问题时很有帮助。此外,我将mod_proxy
配置设置为更接近我喜欢用于这些东西的标准公式。此外,通过运行检查您的虚拟主机设置的输出
sudo apachectl -S
以查看您可以看到的内容。