0

A few weeks ago, I tried to use proxy_pass to make a proxy, in order to display a web page which is not https within my page by using iframe.

it works well, and I just try to set another proxied server, it doesn't work.

conf:

server {
    listen 443 ssl;
    server_name my.com;
    ssl_certificate  /server.pem;
    ssl_certificate_key /server.key;
    root html;
    index index.html index.htm;
    ...
    location /proxy/ {
        proxy_pass http://other.com/;
    }
}

I visit this webpage http://other.com/mobile.html, and it seems work well, but https://my.com/proxy/mobile.html goes wrong, here is the page:

enter image description here

HTTP Status 404 - /somefolder/mobile.html

I suppose that http://other.com server also uses a proxy, so I can't get the real webpage? Anyone knows what happened? Please give me some advice to avoid this.

Any help would be great appreciated! Thanks.

McGrady
  • 101
  • 3
  • You say that `/mobile.html` works well, but does it redirect you to `/somefolder/mobile.html` first? – Richard Smith May 08 '17 at 08:13
  • @RichardSmith No, the url doesn't change. – McGrady May 08 '17 at 08:16
  • 1
    You need to study the HTTP headers sent by your nginx to the upstream server and see if there are any headers missing compared to the request made by the browser. You then need to add values of those headers for the proxy configuration. – Tero Kilkanen May 09 '17 at 14:53
  • @TeroKilkanen Thank you, I set header `X-Application-Context` and it works now. – McGrady May 10 '17 at 01:53
  • @McGrady: It's generally considered bad form to just delete a question after you received help. Please consider undeleting and either ask Tero to write an answer or write your own so others can learn. – Sven May 10 '17 at 11:20
  • @Sven Yeah, I will write an answer. – McGrady May 10 '17 at 12:09

1 Answers1

0

Thanks for @TeroKilkanen's reminding, I realize that my Nginx missed some headers which is very important to other.com.

I tried to compare the response headers of these webpages and I think I understand why this happened.

It seems the server of other.com is using Spring framework, Spring ApplicationContextHeaderFilter adds a X-Application-Context header that contains the ApplicationContext ID. So this header is pretty important, so I tried to add it into Nginx configure file:

location /proxy/ {
    proxy_set_header X-Application-Context ..99;
    proxy_pass http://other.com/;
}

It works at once. Thanks again.

McGrady
  • 101
  • 3