我有一个 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>