/ 404

Nginx配置404允许跨域

这样配置404页面也会有允许跨域的请求头,单独在location下配置add_header是无效的
无效配置

...
location = /404.html {
  add_header 'Access-Control-Allow-Origin' '*';
  add_header 'Access-Control-Allow-Credentials' 'true';
  root   html;
}
...

正确配置

...
 location / {
            add_header 'Access-Control-Allow-Origin' '*' always;
            add_header 'Access-Control-Allow-Credentials' 'true' always;
            root   html;
            index  index.html index.htm;
 }
 error_page 404 /404.html;
 ...

1626743117-1-

Nginx配置404允许跨域
分享