Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm using Nginx to serve static files in response to CORS requests using the technique outlined in this question. However, when the file doesn't exist the 404 response does not contain the Access-Control-Allow-Origin: * header and so is block by the browser.

How can I send Access-Control-Allow-Origin: * on 404 responses?

share|improve this question

1 Answer 1

I'm assuming that you're currently using add_header directive. The documentation notes that this only sets the header for 200, 204, 301, 302 and 304 status code. To set the header for 404 status codes you'll need to use the more_set_headers directive from the headers_more module (you may need to recompile nginx to get this module). The following would set the header for all status codes:

more_set_headers 'Access-Control-Allow-Origin: *';

You can also restrict it to specific status codes:

more_set_headers -s '404' 'Access-Control-Allow-Origin: *';
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.