# Set Incoming Request Headers (similar to mod\_headers)

**URL:** <https://www.ruby-forum.com/t/set-incoming-request-headers-similar-to-mod-headers/179105>\
**Category:** NGINX\
**Created:** [November 17, 2009, 8:46pm UTC](https://www.ruby-forum.com/t/set-incoming-request-headers-similar-to-mod-headers/179105 "2009-11-17T20:46:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![WSandrew\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d07c76/32.png) [@WSandrew\_L](https://www.ruby-forum.com/u/WSandrew_L)\
**Post date:** [November 17, 2009, 8:46pm UTC](https://www.ruby-forum.com/t/set-incoming-request-headers-similar-to-mod-headers/179105/1 "2009-11-17T20:46:39Z")

</div>

I am trying to emulate an Apache mod\_headers feature  
([mod\_headers - Apache HTTP Server Version 2.2](http://httpd.apache.org/docs/2.2/mod/mod_headers.html#requestheader)).  
I would like to set some headers before my content handler is run.  
Specifically SSL related headers that I would like set before my  
Passenger process picks up the request. I could do this with  
proxy\_set\_header, but I am not proxying, the request is being picked  
up and executed by Passenger.

Config looks like this:

location / {  
proxy\_redirect off;  
proxy\_set\_header Host $host;  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_set\_header X-Client-Verify $ssl\_client\_verify;  
proxy\_set\_header X-Client-DN $ssl\_client\_i\_dn;  
proxy\_set\_header X-SSL-Subject $ssl\_client\_s\_dn;  
proxy\_read\_timeout 75;

passenger\_enabled on;  
}

This however will not work, the headers are not set when the backend  
runs. Do I need to setup a second server block listening on a  
different port and then proxy the request to that so I can take  
advantage of proxy\_set\_header, or is there a way to do it like Apache.

---

<div class="post-metadata">

**Author:** ![WSandrew\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d07c76/32.png) [@WSandrew\_L](https://www.ruby-forum.com/u/WSandrew_L)\
**Post date:** [November 18, 2009, 9:03am UTC](https://www.ruby-forum.com/t/set-incoming-request-headers-similar-to-mod-headers/179105/2 "2009-11-18T09:03:31Z")

</div>

On Wed, Nov 18, 2009 at 3:39 AM, W. Andrew Loe III  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am trying to emulate an Apache mod\_headers feature  
> ([mod\_headers - Apache HTTP Server Version 2.2](http://httpd.apache.org/docs/2.2/mod/mod_headers.html#requestheader)).

Oh, I’ve just hacked in the request header support to my  
ngx\_headers\_more module:

```
http://github.com/agentzh/headers-more-nginx-module

```

> I would like to set some headers before my content handler is run.  
> Specifically SSL related headers that I would like set before my  
> Passenger process picks up the request. I could do this with  
> proxy\_set\_header, but I am not proxying, the request is being picked  
> up and executed by Passenger.

The “proxy” module should not be used here because “proxy” is a  
content handler per se (just a little special in that it’s also an  
upstream module) and your have your own content handler (passenger  
here) 🙂

Can you try out the “more\_set\_input\_headers” directive provided by the  
“headers more” module?

Cheers,  
-agentzh
