首页 > 其他 > 详细

nginx的跨域设置

时间:2019-08-18 10:42:47      阅读:92      评论:0      收藏:0      [点我收藏+]

官方文档 中说,只有当响应状态码为以下几种类型中之一时,add_header 才会生效。如果需要 add_header 在所有情况下都生效,可以在后面加上 always 参数即可解决。

Adds the specified field to a response header provided that the response code equals 200, 201 (1.3.10), 204, 206, 301, 302, 303, 304, 307 (1.1.16, 1.0.13), or 308 (1.13.0). The value can contain variables.
There could be several add_header directives. These directives are inherited from the previous level if and only if there are no add_header directives defined on the current level.
If the always parameter is specified (1.7.5), the header field will be added regardless of the response code.

参考配置


server {
    listen 80;
    server_name servername;
    root /var/www/html;
    
    add_header Access-Control-Allow-Origin * always;
    add_header Access-Control-Allow-Methods * always;


    location ~ .php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        include fastcgi.conf;
    }

}

nginx的跨域设置

原文:https://www.cnblogs.com/lovesKey/p/11371242.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!