11

I have multiple apps in Google Play and App Store. These send custom request headers but these headers include an underscore e.g api_key.

The server has now moved from PHP 5.2 on Apache to PHP 5.5 on nginx. On NGINX, apache_request_headers() and getallheaders() are not available.

Is there any way to read custom request headers on NGINX server without having to go and update all apps to remove the underscore? Parsing the $_SERVER variable does not work either - any headers using and underscore are dropped.

shaedrich
  • 5,457
  • 3
  • 26
  • 42
Mark
  • 4,428
  • 14
  • 60
  • 116
  • Have you dumped the `$_SERVER` variable? Are the parameters in there with `HTTP_` prefixed? http://serverfault.com/a/258940 – slapyo Nov 14 '14 at 20:52

1 Answers1

27

You need to set underscores_in_headers on in your NGINX config.

2240
  • 1,547
  • 2
  • 12
  • 30
cryocide
  • 691
  • 5
  • 11
  • which file? nginx 1.10.2, ubuntu 14.04 – Timothy Jan 25 '17 at 13:10
  • 1
    TechyTimo - it can be set in http or server blocks, so typically that's nginx.conf or your vhost file (e.g in /sites_available) – cryocide Jan 26 '17 at 16:28
  • Be warned that ```If the directive is specified on the server level, its value is only used if a server is a default one.``` (from http://nginx.org/en/docs/http/ngx_http_core_module.html#underscores_in_headers) – ElementalStorm Nov 08 '17 at 14:08