1. 程式人生 > >nginx配置允許跨域訪問

nginx配置允許跨域訪問

1、對外提供的查詢訂單資訊介面需要支援跨域訪問:

if ($http_origin ~* ((http|https)?://.*\.aa\.(com|hk)$)) {
  add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
  add_header 'Access-Control-Allow-Origin' $http_origin;
  add_header 'Access-Control-Allow-Credentials' 'true';
  add_header 'Access-Control-Allow-Headers' 'X-Requested-With, Content-Type';
}
2、nginx配置請求轉到https
if ($http_x_proto != SSL) {
    rewrite ^(.*)$  https://$host$1 permanent;
}