Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Some mobile devices send the following incorrect requests to our servers :

GET / HTTP/1.0
User-Agent : xxx

The empty Accept header causes our Ruby on Rails server to throw back a 500 error.

In Apache, the following directive allows us to rewrite the header before sending it to the application RoR server in order to cope with the broken devices :

    RequestHeader edit Accept ^$ "*/*" early

We're currently setting up nginx, but achieving the same work-around is proving difficult. We are able to set :

  proxy_set_header Accept */*;

However, this seems to have to be done inconditionally. Whenever trying to do :

if ($http_accept !~ ".") {
  proxy_set_header Accept */*;

It complains with the message :

"proxy_set_header" directive is not allowed here

So, using nginx, how can we set the HTTP Accept header to */* when it is empty before sending the request to the application server ?

share|improve this question
up vote 1 down vote accepted

Try this

set $acceptHeader $http_accept;
if ($acceptHeader !~ ".") {
  set $acceptHeader '/';
proxy_set_header Accept $acceptHeader;
share|improve this answer
map $http_accept $accept_header {
    default $http_accept;
    ""      */*;    

server {


    proxy_set_header Accept $accept_header;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.