# Add\_header directive not working for 40x and 50x responses

**URL:** <https://www.ruby-forum.com/t/add-header-directive-not-working-for-40x-and-50x-responses/176739>\
**Category:** NGINX\
**Created:** [October 5, 2009, 5:49pm UTC](https://www.ruby-forum.com/t/add-header-directive-not-working-for-40x-and-50x-responses/176739 "2009-10-05T17:49:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fxdemolisher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/b5a626/32.png) [@fxdemolisher](https://www.ruby-forum.com/u/fxdemolisher)\
**Post date:** [October 5, 2009, 5:49pm UTC](https://www.ruby-forum.com/t/add-header-directive-not-working-for-40x-and-50x-responses/176739/1 "2009-10-05T17:49:37Z")

</div>

As per the http header module’s documentation (link) the add\_header  
directive does not work for 40x and 50x error pages.

Is there a specific reason for this? Will the ability to use this  
directive in error pages be added later on?

This is something that is required by my project since NGINX is  
responsible for serving error pages and we need to set specific cookies  
when the error page is displayed.

There is also a post on the ruby nginx forums (link) with this issue  
without a satisfactory answer.

Any information on the issue would be appreciated.

Posted at Nginx Forum:

> **[add\_header directive not working for 40x and 50x responses](https://forum.nginx.org/read.php?2,11280,11280#msg-11280)**
>
> As per the http header module's documentation (\[url=http://wiki.nginx.org/NginxHttpHeadersModule\]link\[/url\]) the add\_header directive does not work for 40x and 50x error pages. Is there a specific reason for this? Will the ability to use this...

---

<div class="post-metadata">

**Author:** ![fxdemolisher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/b5a626/32.png) [@fxdemolisher](https://www.ruby-forum.com/u/fxdemolisher)\
**Post date:** [October 9, 2009, 9:57pm UTC](https://www.ruby-forum.com/t/add-header-directive-not-working-for-40x-and-50x-responses/176739/2 "2009-10-09T21:57:56Z")

</div>

Anyone know an answer to this at all?

Posted at Nginx Forum:

> **[Re: add\_header directive not working for 40x and 50x responses](https://forum.nginx.org/read.php?2,11280,12465#msg-12465)**
>
> As per the http header module's documentation (\[url=http://wiki.nginx.org/NginxHttpHeadersModule\]link\[/url\]) the add\_header directive does not work for 40x and 50x error pages. Is there a specific reason for this? Will the ability to use this...

---

<div class="post-metadata">

**Author:** ![fxdemolisher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/b5a626/32.png) [@fxdemolisher](https://www.ruby-forum.com/u/fxdemolisher)\
**Post date:** [October 10, 2009, 5:07am UTC](https://www.ruby-forum.com/t/add-header-directive-not-working-for-40x-and-50x-responses/176739/3 "2009-10-10T05:07:02Z")

</div>

On Sat, Oct 10, 2009 at 2:12 AM, fxdemolisher [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Anyone know an answer to this at all?

I’ll work on it in a headers-more module and/or provide a patch to add  
an option to the standard headers module 🙂

Cheers,  
-agentzh

---

<div class="post-metadata">

**Author:** ![fxdemolisher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/b5a626/32.png) [@fxdemolisher](https://www.ruby-forum.com/u/fxdemolisher)\
**Post date:** [November 17, 2009, 11:19am UTC](https://www.ruby-forum.com/t/add-header-directive-not-working-for-40x-and-50x-responses/176739/4 "2009-11-17T11:19:31Z")

</div>

On Mon, Oct 5, 2009 at 11:43 PM, fxdemolisher [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> As per the http header module’s documentation (link) the add\_header directive does not work for 40x and 50x error pages.

With the headers\_more module (  
[GitHub - openresty/headers-more-nginx-module: Set, add, and clear arbitrary output headers in NGINX http servers · GitHub](http://github.com/agentzh/headers-more-nginx-module) ), it will by  
default apply to all the status codes, including 4xx and 5xx.

> This is something that is required by my project since NGINX is responsible for serving error pages and we need to set specific cookies when the error page is displayed.

I’m not sure if you want to use nginx variables in your cookies. If  
yes, then headers\_more needs more work to make you happy 🙂

Cheers,  
-agentzh
