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;  //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

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.