CORS with nginx for 401,404,501 and any other http status
After two hours trying to make nginx serve a CORS for a 401 status code, i found the solution and wanted to share it here.
This doc:
http://nginx.org/en/docs/http/ngx_http_headers_module.html#add_header
Says that the "add_header" option only work for status:
200, 201, 204, 206, 301, 302, 303, 304 or 307
But you can bypass all the http status restriction by passing a third parameter to the add_header with the constant "always". That way, it will add the header, all the time, with any state.
So in my case, my header end up like this:
add_header 'Access-Control-Allow-Origin' * always;
Notice the always at the end of the value? That did the trick for me, and just wanted to share it.
Written by Javis V. Pérez
Related protips
1 Response
Thank you, rescuer!
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Nginx
Authors
reiaguilera
279.6K
jamesdullaghan
90.19K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#