返回顶部
扶摇直上九万里,展翅高飞岂可待。

5. nginx跨域配置

1.跨域问题处理:在nginx相关接口上配置如下: 如接口有自己的请求头,则加上:如接口自带请求头pubacc-buid

if ($request_method = "OPTIONS") {

        return 204;

        add_header 'Access-Control-Allow-Origin' '$http_origin';

        add_header 'Access-Control-Allow-Credentials' 'true';

        add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS';

        add_header 'Access-Control-Allow-Headers' 'pubacc-buid,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,Accept,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,*';

        add_header 'Access-Control-Max-Age' '3600';

    }

    if ($request_method = "GET") {

        add_header 'Access-Control-Allow-Origin' "$http_origin";

        add_header 'Access-Control-Allow-Credentials' 'true';

        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';

        add_header 'Access-Control-Allow-Headers' 'pubacc-buid,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,Accept,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,*';

    }

 

    if ($request_method = "POST") {

        add_header 'Access-Control-Allow-Origin' "$http_origin";

        add_header 'Access-Control-Allow-Credentials' 'true';

        add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS';

        add_header 'Access-Control-Allow-Headers' 'pubacc-buid,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,Accept,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,*';

    }

 

2.页面返回带有标准端口处理:将标准版端口切换为请求端口

location ^~ /doc-convert {

  proxy_set_header Host $http_host;

  proxy_set_header x-request-rid $request_id;

  proxy_set_header remote_scheme $scheme;

  proxy_set_header X-Real-IP $remote_addr;

  proxy_set_header X-Forwarded-Proto $scheme;

  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  proxy_http_version 1.1; proxy_set_header Connection "";

  proxy_set_header Accept-Encoding "";

  proxy_redirect http://$host https://$host;

  proxy_pass http://upsdoc-convert;

}

 

posted @ 2022-11-03 14:21  鲤鱼洲畔  阅读(365)  评论(0编辑  收藏  举报