Welcome! Log In Create A New Profile

Advanced

Cannot set cookies when using error_page directive, why?

Posted by pdh0710 
error_page 400 401 402 403 404 500 502 503 504 /err.html;

location = /err.html {
root /var/www;
add_header Set-Cookie "error_response=${status}; path=/;";
}

==========

(Please excuse my English)

Above is a part of my 'nginx.conf'. My purpose is... If error occurred,
client browser gets
'err.html' with error_response=$status cookie. The 'err.html' has JavaScript
codes that
handles the error_response cookie and display related error messages.

However, when I tried "http://test.domain.com/not_exist.html"; and other urls
make error,
the client browser got 'err.html' without error_response cookie.
But when I tried "http://test.domain.com/err.html"; directly, client browser
got error_response
cookie successfully.
So, I concluded Nginx does not pass cookies when using 'error_page'
directive.

Is it a Nginx bug?
Or intentionally blocked? Why?

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,271704,271704#msg-271704

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Richard Stanway
Re: Cannot set cookies when using error_page directive, why?
December 27, 2016 01:30AM
See http://nginx.org/en/docs/http/ngx_http_headers_module.html#add_header

"Adds the specified field to a response header provided that the response
code equals 200, 201, 204, 206, 301, 302, 303, 304, or 307."

If the always parameter is specified (1.7.5), the header field will be
added regardless of the response code.

On Tue, Dec 27, 2016 at 12:37 AM, pdh0710 <[email protected]>
wrote:

> error_page 400 401 402 403 404 500 502 503 504 /err.html;
>
> location = /err.html {
> root /var/www;
> add_header Set-Cookie "error_response=${status}; path=/;";
> }
>
> ==========
>
> (Please excuse my English)
>
> Above is a part of my 'nginx.conf'. My purpose is... If error occurred,
> client browser gets
> 'err.html' with error_response=$status cookie. The 'err.html' has
> JavaScript
> codes that
> handles the error_response cookie and display related error messages.
>
> However, when I tried "http://test.domain.com/not_exist.html"; and other
> urls
> make error,
> the client browser got 'err.html' without error_response cookie.
> But when I tried "http://test.domain.com/err.html"; directly, client
> browser
> got error_response
> cookie successfully.
> So, I concluded Nginx does not pass cookies when using 'error_page'
> directive.
>
> Is it a Nginx bug?
> Or intentionally blocked? Why?
>
> Posted at Nginx Forum: https://forum.nginx.org/read.
> php?2,271704,271704#msg-271704
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Thank you Richard. I fixed the problem.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,271704,271745#msg-271745

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Sorry, only registered users may post in this forum.

Click here to login