Reverse Proxying with nginX, where is the information for redirecting the response stored

It seems like an easy question that should have an easy answer, but I was not able to find it with my searches in the documentation as well as a few tutorials and explanations like this one.

We can implement a reverse proxy with nginX An example configuration might be the code I provide at the bottom. The reverse proxy will accept requests,
forward them to the internal service at http://<myonline-server.mycloud>:<port>/mybar/... and forward back the response to the ip/port that did the request.

My question is, how does it know where to forward the response?

I can think of two possible solutions:

  1. It keeps a lookup table to know where to send it back. If that is the case, it needs to maintain state (lookup table?).
  2. It uses some header on the response that corresponds to a header it set on the internal request (e.g. X_forwarded????). I am not asking if such a header is set or not, I am asking if and when it is used to route back the answer. In this case there is no state maintained, but if the internal server messes up with the response bad things can happen (from not knowing where to send, to sending to wrong out recipient to even mounting a remote dos attack to a random ip…)

Example nginx.conf:

location /foobar/ {
    # I disbled caching so the browser won't cache the site.
    expires           0;
    add_header        Cache-Control private;

    proxy_pass http://<myonline-server.mycloud>:<port>/mybar/;
    proxy_set_header Host $http_host;

    proxy_http_version 1.1;
    proxy_redirect off;
    proxy_buffering off;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

Product of the Month September 2016

Source link

Leave a Comment

Your email address will not be published. Required fields are marked *