【问题标题】:apache2 reverse proxy configurationapache2反向代理配置
【发布时间】:2018-08-08 17:24:49
【问题描述】:

我有一个侦听 TCP 127.0.0.1:81 的应用程序。 我要完成以下重定向:

www.example.com/?requestid=123456 --> http://127.0.0.1:81/?requestid=123456
www.example.com/ANYTHING_ELSE --> MY_IP_THAT_APACHE_LISTENS_ON

我的理解是,如果我不明确重写某些内容,它将遵循 /var/www/html 的常规路径。

我的 /etc/apache2/sites-enabled/000-default.conf 配置:

<VirtualHost *:80>
        ServerName example.com
        ServerAdmin example@example.com
        DocumentRoot /var/www/html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Location />
        RewriteEngine On
        RewriteRule ^/?requestid(.*)$ http://127.0.0.1:81/$1 [P]
        ProxyPassReverse http://127.0.0.1:81/
        Order allow,deny
        Allow from all
    </Location>

</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

为什么它没有正确重写并一直打到正常补丁?

Not Found
The requested URL /bullshit was not found on this server.

Apache/2.4.25 (Debian) Server at example.com Port 80

【问题讨论】:

    标签: apache mod-rewrite mod-proxy


    【解决方案1】:

    来自RewriteRule Directive

    在 VirtualHost 上下文中,Pattern 最初将匹配 主机名和端口之后、查询之前的 URL 部分 字符串(例如“/app1/index.html”)。这是(% 解码的)URL 路径。

    如果您希望匹配主机名、端口或查询字符串, 将 RewriteCond 与 %{HTTP_HOST}、%{SERVER_PORT} 或 %{QUERY_STRING} 个变量。

    所以,你需要这样的东西:

    RewriteEngine On
    RewriteCond %{QUERY_STRING} requestid=(.+)
    RewriteRule ^/$ http://127.0.0.1:81/?requestid=%1 [P]
    

    【讨论】:

      猜你喜欢
      • 2015-05-28
      • 1970-01-01
      • 2016-11-03
      • 2021-03-11
      • 2015-04-26
      • 2017-05-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多