1

I have two pages:

  • PageA.html
  • PageB.html

PageA contains a link to PageB, specified this way:

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

This works perfectly fine as long as PageB is just a regular http page. The link url on PageA is displayed as "http://www.example.com/PageB".

The problem occurs when I change PageB to require https, like so:

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

Now, suddenly the link url on PageA uses the local ip instead of the domain name, this way "https://127.0.0.1/PageB". This means that the visitors on my site cannot access PageB since the url is incorrect.

How come it uses the local ip in the url when PageB uses "@RequireHttps"? I would like the url to use the domain name as before, and only change protocol from http to https.

I am running my webapp in Tomcat 7 under Nginx.

Anders
  • 288
  • 1
  • 10

2 Answers2

3

My issue has now been solved. I found the answer here: https://stackoverflow.com/a/32090722/1826061

Basically, I updated my nginx config like so:

  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;

And then I added this Valve to my Tomcat config:

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

Hopefully it might help others that got the same problem.

Anders
  • 288
  • 1
  • 10
1

HttpsMapper uses HttpServletRequest#getServerName() to create an absolute URL, you'll have to ajdust the name of the <host> element in server.xml.

svenmeier
  • 5,681
  • 17
  • 22
  • I changed the name of the host from: `` To: ``. It did not help. Still got the same problem with the url in the link being 127.0.0.1.` – Anders Jun 21 '18 at 08:12