我希望Apache以下列方式工作:
我试过这几种方式:
方法1:
RewriteRule ^(.*) http://xxx.xxx.xxx:port/ [P]
结果:重定向循环,远程IP被访问了几次(可以通过查看远程服务器上的日志来确认)。 SERVER1的日志显示重复以下内容:
proxy: *: found reverse proxy worker for http://xxx.xxx.xxx/
mod_proxy.c(1020): Running scheme http handler (attempt 0)
mod_proxy_http.c(1973): proxy: HTTP: serving URL http://xxx.xxx.xxx/
proxy_util.c(2011): proxy: HTTP: has acquired connection for (*)
proxy_util.c(2067): proxy: connecting http://xxx.xxx.xxx/ to xxx.xxx.xxx:80
proxy_util.c(2193): proxy: connected / to xxx.xxx.xxx:80
proxy_util.c(2444): proxy: HTTP: fam 2 socket created to connect to *
proxy_util.c(2576): proxy: HTTP: connection complete to xxx.xxx.xxx:80 (xxx.xxx.xxx)
mod_proxy_http.c(1743): proxy: start body send
mod_proxy_http.c(1847): proxy: end body send
proxy_util.c(2029): proxy: HTTP: has released connection for (*)
方法2:
<VirtualHost *:801>
ServerName SERVER1
ProxyRequests Off
ProxyPreserveHost On
<Proxy *:801>
Order deny,allow
Allow from localhost
</Proxy>
ProxyPass / http://xxx.xxx.xxx/
ProxyPassReverse / http://xxx.xxx.xxx/
LogLevel debug
</VirtualHost>
和
RewriteRule ^(.*) http://127.0.0.1:801/ [PT]
结果:400错误请求 使用method2,我可以在浏览器中转到SERVER1:801,一切都按预期工作。
非常感谢任何帮助! 提前谢谢!
答案 0 :(得分:0)
该解决方案最终成为了apache中几种不同工具的组合:
ProxyPassInterpolateEnv On
和interpolate
语句的末尾使用ProxyPass
和ProxyPassReverse
关键字)的Apache:
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from localhost
</Proxy>
RewriteEngine On
ProxyPassInterpolateEnv On
RewriteMap subdomains txt:/directory/clients.txt
RewriteCond %{HTTP_HOST} ^(.*)\.application\.com
RewriteRule ^ - [E=SERVER_NAME:${subdomains:%1}]
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ %{REQUEST_URI}/ [R]
ProxyPass / http://${SERVER_NAME}/ interpolate
ProxyPassReverse / http://${SERVER_NAME}/ interpolate