1

When i set Host header sent to upstream server to $proxy_host i get the the requested page but the url is changed in the browser to the upstream url.

...
proxy_set_header Host $proxy_host;
proxy_pass ...

the above works fine except that the url in the browser changes and shows the upstream url instead of the url that the user entered - we want the user's url to be shown

To remedy that When i send $host instead then i get an error in the browser saying that connection was refused.

...
proxy_set_header Host $host;
proxy_pass ...

This gives the connection was refused error - I am not sure if this error is generated by nginx or it is generated by my upstream server. I do not control much about what the upstream server expects as that is a call to s3 storage (object storage) over http on DO.

Is there a way to diagnose where the error is coming from and if it is from the upstream server how can i still have the user get the same url in their browser while passing the $proxy_host to the upstream?

Does passing $proxy_host to the upstream affect the user's browser? By what mechanism?? Should it not only affect what is going to the upstream server? Why does the browser behavior change? Please can anyone shed light on this behavior? Thank you in advance.

*EDIT - including full server context below as requested:

server {
        listen       80;
        server_name  example.com;
        location / {
        rewrite ^(.*)/$ $1/index.html break;
        rewrite ^(.*/[^./]+)$ $1/index.html break;
        proxy_set_header Host $proxy_host;
        proxy_pass http://someotherexample.com;
        }
}
0

2 Answers 2

1

The mystery is solved! Posting here so that it may help someone in a similar situation at any point in the future...

The issue was with https 'upgrade' automatically happening at upstream and setting up of hsts headers. These headers were being passed on to client side browser forcing it to make another request with https which my server block listening on port 80 was not handling - thus causing the anomalies.

I changed the proxy_pass call to https which solved the issue because then the upstream stopped trying to enforce https by sending headers that made the client side go wonky and do unexpected things. Now my client browser is still doing http call which we wanted as part of our overall design and we get what we wanted in the browser while still fetching the right content in the browser without showing the upstream url in the browser.

0

This has nothing to do with proxy configuration, and clearly is configured on the upstream side.

In general, your initial post contains several issues described, so you should separate them into multiple questions. The majority of those could be answered by just opening the stock documentation from http://nginx.org/en/docs/.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .