Score:0

Nginx config on reverse proxy for custom headers from backend to client

us flag

Nginx (19.x) is used as reverse proxy for nodejs backend server (ubuntu). Here is the nginx conf file for reverse proxy:

server {
  listen 80;

  location /api {
    proxy_pass http://127.0.0.1:5000;  //proxy pass for nodejs backend server. Will it pass value of non-empty custom headers as well?? 
  }
}

Both the client and backend server may set custom header for request and response. My understanding is that nginx passes all non-empty custom headers from client to backend server by default. Is there additional config required on nginx to pass custom headers from backend to client? There is proxy_set_header in nginx document but I am not sure if it is for backend to client.

Here is example of custom header defined on backend server.

                res.setHeader("x-auth-token", token);  //custom header 
                res.setHeader("x-auth-token-rsa", tokenRSA); //custom header
                res.setHeader("x-auth-secret",  secret);    //custom header
Score:1
us flag

proxy_set_header is meant to set additional headers when nginx proxies the client's request to backend server.

One use-case for this is to tell original client's IP address to backend server:

proxy_set_header X-Real-IP $remote_addr;

nginx forwards the responses from the server as-is, including all the headers. You don't need to configure anything for it.

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.