我在工作中遇到了一个 cofig 文件,但我不确定语法是否正确。根据 apache 的文档:https://httpd.apache.org/docs/current/mod/mod_proxy.html#proxy 代理指令的上下文是“虚拟主机”,这绝对正确。似乎有下面这样的配置是完全没问题的(这是我在工作中遇到的配置)
<VirtualHost *:80>
ServerName myexample.com
Redirect / https://myexample.com/
</VirtualHost>
<VirtualHost *:443>
ServerName myexample.com
SSLEngine On
SSLCertificateFile locationofcert.crt
SSLCertificateKeyFile locationofkey.key
ProxyTimeout 300
ProxyRequests on
ProxyPreserveHost On
ProxyPass / http://myexample.com:7990/
ProxyPassReverse / http://myexample.com:7990/
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
</VirtualHost>
我的具体问题是关于这部分:
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
我注意到在 github 中的一些示例中,这个代理指令被放置在 Location 标签内,如下所示:
<Location />
ProxyPass http://localhost:9000/
ProxyPassReverse http://localhost:9000/
Order allow,deny
Allow from all
</Location>
我正在尝试找出正确的语法。任何文档链接都将不胜感激。谢谢!
答案1
从语法上来说,两者都是正确的。选择应该完全基于需求。
也可以将整个<Location>
块放在 里面<VirtualHost>
。例如,上面的代码可以重写为:
<VirtualHost *:80>
ServerName myexample.com
Redirect / https://myexample.com/
</VirtualHost>
<VirtualHost *:443>
ServerName myexample.com
SSLEngine On
SSLCertificateFile locationofcert.crt
SSLCertificateKeyFile locationofkey.key
ProxyTimeout 300
ProxyRequests on
ProxyPreserveHost On
<Location />
ProxyPass http://myexample.com:7990/
ProxyPassReverse http://myexample.com:7990/
Order deny,allow
Allow from all
</Location>
</VirtualHost>