代码片段

作者: 敖武

nginx header 添加与删除

接口和前端部署在不同与名下时可以通过nginx 添加cors header解决跨域问题

添加 header

location / {
    ...
    add_header X-Frame-Options SAMEORIGIN;
    add_header X-Content-Type-Options nosniff;
    add_header Access-Control-Allow-Origin *; # 允许跨域访问
}

删除 header

网站博客部署在OSS上,访问oss的页面时都会自动下载, 原因是:响应头中添加了x-oss-force-downloadContent-Disposition: attachmeng等字段, 导致浏览器自动下载,故通过nginx转发时需要对header进行操作

location / {
    ...
    proxy_hide_header Content-Disposition;
    proxy_hide_header x-oss-force-download;
}