By default Nginx only adds headers for requests it considers successful. You can make it add the header without regard for the response code, by adding the always
parameter to your add_header
directive, e.g.
add_header 'Access-Control-Allow-Origin' '*' always;
Adding the always
parameter to the Access-Control-Allow-Origin
header is not enough. The always
parameter needs to be added to the headers that need to be always added. In some cases, you will need to add the always
parameter to the Access-Control-Allow-Credentials
header.
add_header 'Access-Control-Allow-Credentials' 'true' always;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…