![仅当远程地址位于子网中时才使用 ProxyPass](https://linux22.com/image/790991/%E4%BB%85%E5%BD%93%E8%BF%9C%E7%A8%8B%E5%9C%B0%E5%9D%80%E4%BD%8D%E4%BA%8E%E5%AD%90%E7%BD%91%E4%B8%AD%E6%97%B6%E6%89%8D%E4%BD%BF%E7%94%A8%20ProxyPass.png)
我有一个 php 应用程序正在运行,其配置大多为默认配置var/www/html/app
:
<VirtualHost *:443>
ServerName myhost.com
DocumentRoot /var/www/html
<Directory "/var/www/html">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
# etc...
</VirtualHost>
我有在代理后运行的第二个版本的应用程序:
<Location "/app/">
ProxyPreserveHost On
ProxyPass http://127.0.0.1:8080/
ProxyPassReverse http://127.0.0.1:8080/
</Location>
我想通过仅将特定子网上的用户定向到代理来进行 A/B 测试。我尝试了以下几种方法,就访问而言,这种方法似乎部分有效,但如果任何位置通过,它仍会使用代理:
<Location "/app/">
Order deny,allow
Deny from all
Allow from 192.168.16.0/24
ProxyPreserveHost On
ProxyPass http://127.0.0.1:8080/
ProxyPassReverse http://127.0.0.1:8080/
</Location>
<Location "/app/">
Allow from all
</Location>
我是否试图实现该Location
指令无法处理的事情?
答案1
我使用带有代理标志的重写引擎使其工作:
<VirtualHost *:443>
RewriteEngine On
# Match the subnet
RewriteCond expr "-R '192.168.14.0/24'"
# Proxy to the container (removing /app)
RewriteRule ^/app/(.*) http://127.0.0.1:8080/$1 [P]
ProxyPassReverse /app/ http://127.0.0.1:8080/
# I need these settings for the proxied server
ProxyPreserveHost On
RequestHeader set X-Forwarded-Prefix "/app"
</VirtualHost>