apache2反向代理配置

apache2反向代理配置,apache,mod-rewrite,mod-proxy,Apache,Mod Rewrite,Mod Proxy,我有一个应用程序监听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的常规路径 My/etc/apache2/sites en

我有一个应用程序监听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的常规路径

My/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
发件人:

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

如果希望与主机名、端口或查询字符串匹配, 对%{HTTP\u HOST}、%%{SERVER\u PORT}或 %分别为{QUERY_STRING}个变量

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

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