【问题标题】:Wicket incorrect bookmarkable page url when using https使用 https 时检票不正确的可收藏页面 url
【发布时间】:2023-04-11 04:41:01
【问题描述】:

我有两页:

  • PageA.html
  • PageB.html

PageA 包含指向 PageB 的链接,指定方式如下:

add(new BookmarkablePageLink<Void>("link", PageB.class, parameters));

只要 PageB 只是一个普通的 http 页面,它就可以正常工作。 PageA上的链接url显示为“http://www.example.com/PageB”。

当我将 PageB 更改为需要 https 时出现问题,如下所示:

@RequireHttps
public class PageB extends WebPage {
    ...
}

现在,PageA 上的链接 url 突然使用本地 ip 而不是域名,即“https://127.0.0.1/PageB”。这意味着我网站上的访问者无法访问 PageB,因为 url 不正确。

PageB 使用“@RequireHttps”时,怎么会在 url 中使用本地 ip? 我希望 url 像以前一样使用域名,并且只将协议从 http 更改为 https。

我在 Nginx 下的 Tomcat 7 中运行我的 webapp。

【问题讨论】:

    标签: java apache nginx https wicket


    【解决方案1】:

    我的问题现在已经解决了。我在这里找到了答案:https://stackoverflow.com/a/32090722/1826061

    基本上,我更新了我的 nginx 配置,如下所示:

      proxy_set_header X-Forwarded-Host $host;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP  $remote_addr;
      proxy_set_header X-Forwarded-Server $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto  $scheme;
    

    然后我将此 Valve 添加到我的 Tomcat 配置中:

    <Valve className="org.apache.catalina.valves.RemoteIpValve"  
           remoteIpHeader="X-Forwarded-For"  
           protocolHeader="X-Forwarded-Proto"  
           protocolHeaderHttpsValue="https"/> 
    

    希望它可以帮助遇到同样问题的其他人。

    【讨论】:

      【解决方案2】:

      HttpsMapper 使用 HttpServletRequest#getServerName() 创建绝对 URL,您必须在 server.xml 中调整 &lt;host&gt; 元素的名称。

      【讨论】:

      • 我把主机名从:&lt;Host name="localhost" ....&gt;改为:&lt;Host name="example.com" ....&gt;。它没有帮助。链接中的 url 仍然是 127.0.0.1 的问题。`
      猜你喜欢
      • 2013-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多