带有重写模式的 apache 反向代理

带有重写模式的 apache 反向代理

我正在使用重写模式在我的 apache 反向代理上配置一个新的虚拟主机,测试配置时一切正常,但只有一个页面(图像页面)无法正常工作。单击图像页面时,我在浏览器中获取本地 URL(https://本地服务器:9251 /共享/ collab?collabSession = ea4a80bf-6c19-473b-ad08-bdce391dbe19&type = join&user =用户名&isInitiator = true)。

ports.conf 中已激活端口 9251、433 和 80

下面是我的虚拟主机配置:

<VirtualHost *:80>
    ServerName publicdomaine.com
    ServerAlias www.publicdomaine.com
    Redirect Permanent / https://publicdomaine.com
</VirtualHost>

<VirtualHost *:443>
    ServerName publicdomaine.com
    ServerAlias www.publicdomaine.com

    <IfModule mod_proxy.c>
        SetEnv proxy-nokeepalive 1

        SetEnv proxy-initial-not-pooled 1
        ProxyRequests Off
        ProxyPreserveHost Off

        ProxyPass / https://localserver/
        ProxyPassReverse / https://localserver/
    </IfModule>

    SSLEngine on
    SSLProxyEngine On
    SSLProxyVerify none
    SSLProxyCheckPeerCN off
    SSLProxyCheckPeerName off
    SSLProxyCheckPeerExpire off
    SSLCertificateKeyFile /etc/apache2/cert/mykey.pem
    SSLCertificateFile /etc/apache2/cert/mycert.pem
    SSLCertificateChainFile /etc/apache2/cert/bundle.crt

    RewriteEngine On
    LogLevel alert rewrite:trace6

    RewriteCond %{QUERY_STRING} ^(.*)&studyUid=(.*)
    RewriteCond %{QUERY_STRING} ^host=publicdomaine.com(.*)$
    RewriteRule ^/ris/web/imageshare/startSession - [E=SUI_VAL:%1]

    RewriteRule /ris/web/imageshare/startSession https://localserver/ris/web/imageshare/startSession?host=cimcsp1.cimy.local%{ENV:SUI_VAL} [P,QSA,L]

    ErrorLog /var/log/signoff-error_log

    CustomLog /var/log/signoff-access_log combined
</VirtualHost>

<VirtualHost *:9251>
    SetEnv proxy-nokeepalive 1
    SetEnv proxy-initial-not-pooled 1
    ProxyRequests Off
    ProxyPreserveHost Off

    ProxyPass / https://localserver:9251/
    ProxyPassReverse / https://localserver:9251/
</VirtualHost>

我观察了与 fiddler 的 http 交换。消息交换:

GET https://publichostname/ris/web/imageshare/startSession?host=publichostname&studyUid=1.3.51.0.1.1.10.233.24.237.333827.7779290494 HTTP/1.1

反向代理将参数 host 重写为 localserver :

GET https://publichostname/ris/web/imageshare/startSession?host=localserver&studyUid=1.3.51.0.1.1.10.233.24.237.333827.7779290494 HTTP/1.1

响应为 JSON:

{"initiatorLink":"https://localserver:9251/share/collab?collabSession=74bea62c-474a-4ee5-9d74-e793fef66738&type=join&user=username&isInitiator=true","studyUid":"1.3.51.0.1.1.10.233.24.237.333827.7779290494","baseLink":"https://localserver:9251/share/?collabSession=74bea62c-474a-4ee5-9d74-e793fef66738","closedLink":null}

此回复引导我:

CONNECT localserver:9251 HTTP/1.1
Host: localserver:9251

这应该是通过反向代理将我隧道传输到:

CONNECT publichostname:9251 HTTP/1.1
Host: publichostname:9251

答案1

最好的选择是配置您的应用程序服务器以生成可与代理一起使用的正确 URL。

但是,如果你不能这样做,你可以使用另一个 Apache 模块,mod_proxy_html.该模块提供指令ProxyHTMLURLMap,您可以使用它来重写响应。

ProxyPass / https://localserver/
ProxyPassReverse / https://localserver/
SetOutputFilter proxy-html # make sure the output is filtered by proxy-html
ProxyHTMLURLMap https://localserver:9251/ https://publichostname:9251/
ProxyHTMLExtended On       # by default only HTML output is filtered

这应该使用 publichostname URL 重写答案中所有出现的 localserver URL。

请注意,这会给 Web 服务器带来额外的负载,因为它必须分析和修改每个答案,而不是仅仅传递答案。正确配置应用服务器将是首选方法。

答案2

找到了!我已经添加了替代模式来修改服务器响应,并且它起作用了 !!!!! 命令添加:

AddOutputFilterByType SUBSTITUTE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript application/json
Substitute "s|https:\/\/localserver:9251|https:\/\/publichostname:9251|ni"

谢谢你的帮助!!!!

相关内容