大网数据广告活动
服务器运维问答

Syntax of proxy directive in virtual host - httpd

· 52CE 我爱测

I came across a cofig file at work, but I am unsure if the syntax is correct. Based on the documentation from apache: https://httpd.apache.org/docs/current/mod/mod_proxy.html#proxy the proxy directive's context is "virtual host",…

问题原文

原帖链接 · Rakim · CC BY-SA 4.0

I came across a cofig file at work, but I am unsure if the syntax is correct. Based on the documentation from apache:https://httpd.apache.org/docs/current/mod/mod_proxy.html#proxy the proxy directive's context is "virtual host", which is absolutely correct. It seems it's perfectly fine to have a config like this one below (which is the one I came across at work)

<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>

My specific question is about this part:

<Proxy *>
    Order deny,allow
    Allow from all
</Proxy>

I have noticed in some examples in github that, this proxy directive is placed inside a Location tag like this:

<Location />
       ProxyPass http://localhost:9000/
       ProxyPassReverse http://localhost:9000/
       Order allow,deny
       Allow from all
</Location>

I am trying to find out what the correct syntax is. Any links to documentation would be appreciated too. Thanks!

已采纳解答

原帖链接 · Chaminda · CC BY-SA 4.0

Syntax-wise, both are correct. Choice should be entirely based on the requirement.

It is also possible to place the whole <Location> block inside a <VirtualHost>. For instance, your above code can be rewritten as:

<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>

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-10-29)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。