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 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试