Can I turn off an Apache Directive then turn it on in an include?

泄露秘密 提交于 2019-12-13 07:30:15

问题


I have a VirtualHost block that includes common configuration items, one directive is ProxyPreserveHost.

Can I "procedurally" turn off ProxyPreserveHost for a Rewrite directive then have the include turn it back on? For example:

<VirtualHost *:80>
ServerName www.blah.com
...
...
ProxyPreserveHost off
RewriteRule /somepath http://otherhost/otherpath [P]

Include /path/to/file/turning-on-ProxyPreserveHost

</VirtualHost>

The otherhost is on a CDN and preserving the host is creating some name resolution issue that is not allowing the proxying of content in the host namespace.

ProxyReserveHost is only allowed in a Server Config or VirtualHost. It doesn't look like I can selectively turn it off for the ProxyPass and ProxyPassReverse directives (encapsulated in the proxy flag of mod_rewrite).


回答1:


The following, found on the internet, addressed my dilemma. As an aside, there is an open feature request to make ProxyPreserveHost configurable at the Location and Directory level within the Apache HTTPD project.

<IfModule mod_headers.c>
  <Proxy "http://${build.replace.host}/">
    RequestHeader set Host ${build.replace.external.host}
  </Proxy>
  RewriteRule      ^/proxypath/ http://${build.replace.external.host}/path/to/resource.html [P]
  ProxyPassReverse /proxypath/ http://${build.replace.external.host}/path/to/resource.html
</IfModule>


来源:https://stackoverflow.com/questions/2427874/can-i-turn-off-an-apache-directive-then-turn-it-on-in-an-include

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!