Passing custom server headers to php running under Nginx

Nginx doesn’t seem to pass any additional custom header to $_SERVER variable. To make this happen you need to:

1. First the custom http header sending out (from your REST client) need to use dash instead of underscore, for example “HTTP-X-REST-USERNAME”.

2. On the server side, in your fastcgi_params file (/etc/nginx/fastcgi_params) add this:

fastcgi_param   HTTP_X_REST_USERNAME    $http_x_rest_username;

3. Restart server you will see $_SERVER[‘HTTP_X_REST_USERNAME’] inside php land.

Leave a Reply