允许Cors跨域访问,配置文件报错。如下图:
我是这样配置的,
代码如下:
- #SSL-END
- #配置允许baidu.com的Cors请求1
- add_header 'Access-Control-Allow-Origin' "$http_origin";
- add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
- add_header 'Access-Control-Allow-Credentials' 'true';
- add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
- add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
- if ($request_method = 'OPTIONS') {
- return 204;
- }
- #配置允许baidu.com的Cors请求2
- if ($http_origin ~* (https?://baidu.com(:[0-9]+)?$)) {
- add_header 'Access-Control-Allow-Origin' "$http_origin";
- add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
- add_header 'Access-Control-Allow-Credentials' 'true';
- add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
- }
复制代码
|
|