Nginx – Inject cookie with Nginx reverse proxy

nginxreverse-proxy

With Nginx as a reverse proxy I'd like to inject a cookie for backend systems to consume.

location /delegate {
  proxy_pass                        <some-url>;
  proxy_set_header Host             $host;
  proxy_set_header X-Forwarded-For  $remote_addr;
  proxy_set_header X-Request-ID     $request_id;
  # some more
  # here: inject a new cookie into `cookie` request header
}

As I want the cookie to be consumed by downstream systems this isn't about the add_header Set-Cookie instruction (which is for the response going back to the client).

Best Answer

You can provide server with cookies via

proxy_set_header Cookie "name=john; age=30; male=1";