dongyuan8024 2019-02-19 09:23
浏览 156
已采纳

如何修复逆向代理服务器后面的wordpress站点的URL

I have a WordPress site on IIS 8, let's call it www.mysite.com, that I need to isolate behind a proxy server (with IIS 10).

What I have done so far is:

  • changed siteurl and home to site.mysite.com (to avoid continuos redirect)
  • added site www.mysite.com in new server with reverse proxy to site.mysite.com (defined in hosts file as old server ip alias) configured as follow
    <configuration>
        <system.webServer>
            <rewrite>
                <outboundRules rewriteBeforeCache="true">
                    <clear />
                    <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1" enabled="true">
                        <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^http(s)?://site.mysite.com/(.*)" />
                        <conditions logicalGrouping="MatchAll" trackAllCaptures="true" />
                        <action type="Rewrite" value="http{R:1}://www.mysite.com/{R:2}" />
                    </rule>
                    <rule name="RestoreAcceptEncoding" preCondition="NeedRestoringAcceptEncoding" enabled="true">
                        <match serverVariable="HTTP_ACCEPT_ENCODING" pattern="^(.*)" />
                        <conditions logicalGrouping="MatchAll" trackAllCaptures="true" />
                        <action type="Rewrite" value="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" />
                    </rule>
                    <preConditions>
                        <preCondition name="ResponseIsHtml1">
                            <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                        </preCondition>
                        <preCondition name="NeedRestoringAcceptEncoding">
                            <add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+" />
                        </preCondition>
                    </preConditions>
                </outboundRules>
                <rules>
                    <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                        <match url="(.*)" />
                        <action type="Rewrite" url="https://site.mysite.com/{R:1}" />
                        <serverVariables>
                            <set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" />
                            <set name="HTTP_ACCEPT_ENCODING" value="" />
                        </serverVariables>
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>
    

Unfortunately this isn't enough.

Despite the reverse proxy outbound rule, many scripts, css links and images point to site.mysite.com (which is not exposed to the internet) instead of www.mysite.com.

Is there a way to fix those links making them refer to www?

Are there better solutions?


I have never worked with WordPress/PHP and have no knowledge how it builds those urls, so if you need any clarification please be as specific as possible thus I can improve my question.

UPDATE

If I configure

  • in isolated server
    • siteurl and home to www.mysite.com
    • set 127.0.0.1 www.mysite.com in hosts file
  • in exposed server
    • IIS 10 site binding www.mysite.com with forward rule to www.mysite.com
    • set WORDPRESS_SERVER_IP www.mysite.com in hosts file

I get following IIS error:

Errore HTTP 400.605 - Bad Request The request cannot be routed because it has reached the Max-Forwards limit. The server may be self-referencing itself in request routing topology.

  • 写回答

1条回答 默认 最新

  • doupao3662 2019-02-20 21:38
    关注

    You should set the siteurl and home variables to the value of the proxy server.

    If you're exposing your server to the public at www.mysite.com then you should set the same values in those variables.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?