Nginx services fail for cross-domain requests if the service returns an error

I am making a cross-domain request in my web application.

I set the CORS headers on Nginx. Everything works fine, except when the service returns an error, for example, 404, 400, 500, etc. Instead of receiving an error code, the service does not work with an error saying that Origin *********** is not allowed by Access-Control-Allow-Origin.

Any ideas why this could be happening?

+5
source share
2 answers

The answer is found here :

Unfortunately, add_header will not work with status codes other than 200, 204, 301, 302 or 304. Here you can find it in the documentation.

You can use this plugin to accomplish what you want:

http://wiki.nginx.org/NginxHttpHeadersMoreModule

+7

1.1.5 nginx, "" add_header, .

+6

All Articles