mod_setenv: Lighttpd Send Custom Headers

in Categories last updated March 26, 2010

How do I add a header to the HTTP request that was received from the client under Lighttpd web server?

You can use the setenv module (mod_setenv) which allows influencing the environment external applications are spawned in and the response headers the server sends to the clients. Edit lighttpd.conf, enter:
# vi /etc/lighttpd/lighttpd.conf
Add mod_setenv:

server.modules += ( "mod_setenv" )

Set X-proxy header:

setenv.add-response-header = ( "X-Proxy" => "www-02" )

Or sent server itself:

setenv.add-request-header = ( "X-Proxy" => server.name )

Save and close the file. Reload lighttpd:
# service lighttpd reload
To see headers, enter:
$ curl -I http://example.com/

References:

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Share this on (or read 1 comments/add one below):

1 comment

  1. For some reason it did not work for me correctly.

    I tried setenv.add-response-header = ( “Access-Control-Allow-Origin” => “*” )

    since Chrome was not able to load MathJax fonts. Only some files were stamped within their header. I do not understand well the reasoning but it started to work when I moved the above line into the current host section:

    $HTTP["host"] =~ "mathjax" {
      setenv.add-response-header = ( "Access-Control-Allow-Origin" => "*" )
    }
    

    Have a question? Post it on our forum!