How to return a cookie to a client when auth_request is used?

nginxuser100 nginx-forum at
Thu Jan 15 08:11:23 UTC 2015


Question 1:

I would like to have an FastCGI authentication app assign a cookie to a
client, and the Fast Auth app is called using auth_request. The steps are as

1. Client sends a request
2. NGINX auth_request forwards the request to a FastCGI app to
3. The authentication FastCGI app creates a cookie, using "Set-Cookie:
name=value". I would like this value to be returned to the client.
4. Assuming the authentication was successful, NGINX then forwards the
request to an upstream FastCGI app which sends a response to the client. The
HTTP header should contain Set-Cookie: name=value

How do I get NGINX to include the cookie in the header that gets forwarded
to the upstream module so the final response to the client contains the
cookie? I tried using auth_request_set but got 

    location / {
        auth_request /auth;
        include fastcgi_params;
        fastcgi_param  HTTP_COOKIE $http_cookie;
        #auth_request_set $http_cookie "test";  <======= I tried this just
to see how auth_request_set works. NGINX j

    # new fastcgi to set the cookie
    location /auth {
        include fastcgi_params;

Question 2.    I also tried 
       auth_request_set $http_cookie "test";  
       to see how auth_request_set works. NGINX gave me this error at start

nginx: [emerg] the duplicate "http_cookie" variable in

Why did get such error?

Question 3. Can someone give me a pointer to a list of NGINX FastCGI
supported env variables such as $http_cookie / HTTP_COOKIE?

Thank you!

Posted at Nginx Forum:,256110,256110#msg-256110

More information about the nginx mailing list