2

我希望 Apache 以下列方式工作:

  1. 用户在地址栏中键入 user1.app.com。
  2. DNS 有一个通配符,可以将所有内容转发到 SERVER1
  3. SERVER1 运行 Apache,它将使用重写映射将 user1 映射到 IP 地址 xxx.xxx.xxx。
  4. Apache 提供来自 xxx.xxx.xxx 的所有内容,同时保留 URL user1.app.com

我尝试了几种方法:

方法一:

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 (*)

方法二:

<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 错误请求使用方法 2,我可以在浏览器中转到 SERVER1:801,一切都按预期工作。

任何帮助是极大的赞赏!提前致谢!

4

1 回答 1

0

该解决方案最终是 apache 中几种不同工具的组合:

  • 使用文本文件将每个子域映射到适当的 IP
  • 代理重定向中访问子域的环境变量的插值(必须在and语句的末尾使用ProxyPassInterpolateEnv Onand关键字)interpolateProxyPassProxyPassReverse

阿帕奇:

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
于 2014-01-21T18:51:10.923 回答