Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

I am making a cross domain request in my web app.

I have set the CORS headers on Nginx. Everything is working fine except when the service returns an error like 404, 400, 500 etc, instead of receiving the error code, the service is failing with an error saying that the Origin *********** is not allowed by Access-Control-Allow-Origin.

Any ideas why this might be happening?

This is what the nginx setting looks like;

location /api {
    add_header Access-Control-Allow-Origin *;
share|improve this question
I have set the CORS headers on Nginx. --> could you please show us? – quanta Sep 24 '12 at 6:57
@quanta Edited the question... – Niyaz Sep 24 '12 at 7:01
up vote 1 down vote accepted

Unfortunately add_header won't work with status codes other than 200, 204, 301, 302 or 304. You can find this in the documentation here.

You may be able to use this plugin to do what you want:

share|improve this answer

I can confirm that the headers_more module (mentioned in this answer) can be used to add headers for all HTTP responses, regardless of status code.

Note: You may need the workaround at to build this module with Nginx on Windows, but it works as expected once compiled in.

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.