Score:0

Reverse Proxy connecting to the site, but is using the wrong ip address for file requests

mu flag

I am trying to set up a connection between two servers so when one is accessed the client is proxied to the second one.

http {

        upstream serverConn {
                server <my.server.ip>;
        }

        server {
        listen 80 default_server;

        root /usr/share/nginx/html;

                location /test {
                        proxy_pass http://serverConn/;
                        proxy_set_header Host $upstream_addr;
                        proxy_set_header X-Forwarded-For $remote_addr;
                        proxy_set_header X-Forwarded-Host $http_host;
                }
        }
}

When a client accesses the server, it is supposed to proxy them to <my.server.ip>, but all of the get requests made on the webpage are looking for files on the server hosting nginx.

The URL that triggers the error

Here is a picture of the request made with the wrong ip, it should be <my.server.ip> instead of 10.XXX.XX.X which is the nginx server. Is there any solution to this? I tried many variations of set_header to no avail.

Jessie avatar
cl flag
You are only proxying paths that begin with `/test` but the URL in the photo begins with `/static/`
Jessie avatar
cl flag
Also it's better to simply include the URL as text instead of an image, since images are more likely to expire which makes it difficult for future readers.
djdomi avatar
za flag
Does this answer your question? [Proxy HTTPS requests to a HTTP backend with NGINX](https://serverfault.com/questions/145383/proxy-https-requests-to-a-http-backend-with-nginx)
Score:0
vn flag

"it is supposed to proxy them to <my.server.ip>" is in general not true. Modern web apps must be written in a way that works well with reverse proxy, but many are not.

In your case, the difference between href="static/some.css" and href="/static/some.css" matters a lot, and the latter does not work with your proxy settings.

In the first example, static/some.css is a relative path that specifies the location of the CSS file relative to the location of the HTML file. This means that if your HTML file is located in a directory called mywebsite, then the CSS file should be located in a subdirectory called static within the mywebsite directory.

In contrast, /static/some.css is an absolute path that specifies the location of the CSS file relative to the root directory of your website. This means that no matter where your HTML file is located within your website’s directory structure, it will always look for an static subdirectory within your website’s root directory to find the CSS file.

So, to resolve the issue you should go back to the web app itself and fix all such paths.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.