美文网首页
nginx跨域

nginx跨域

作者: 从不放弃 | 来源:发表于2019-05-31 15:23 被阅读0次
server {
    listen       80;
    server_name  xxx.com;

    location /xxx-web/papi {
        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' 'DNT,web-token,app-token,Authorization,Accept,Origin,Keep-Alive,User-Agent,X-Mx-ReqToken,X-Data-Type,X-Auth-Token,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') {
            add_header 'Access-Control-Max-Age' 1728000;
            add_header 'Content-Type' 'text/plain; charset=utf-8';
            add_header 'Content-Length' 0;
            return 204;
        }
        root   html;
        index  index.html index.htm;
        proxy_pass http://127.0.0.1:7071;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_connect_timeout 5;
    }
 
    location /xxx-web {
        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' 'DNT,web-token,app-token,Authorization,Accept,Origin,Keep-Alive,User-Agent,X-Mx-ReqToken,X-Data-Type,X-Auth-Token,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') {
            add_header 'Access-Control-Max-Age' 1728000;
            add_header 'Content-Type' 'text/plain; charset=utf-8';
            add_header 'Content-Length' 0;
            return 204;
        }
        root   html;
        index  index.html index.htm;
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_connect_timeout 5;
    }
 
    location / {
        root   /var/www/xxx/wechat/webroot;
        index  index.html index.htm;
    }
 
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}

相关文章

  • 浏览器跨域的那些事

    整理中 目标: 了解跨域 解决跨域 服务器配置跨域(java, nginx) 前端调试时配置解决跨域 一、什么是跨...

  • nginx反向代理

    前端调用接口的时候跨域了怎么办呢,如下代码跨域: 通过nginx反向代理下载nginx:http://nginx....

  • 关于设置env等环境变量的思考

    1、如何处理跨域后台处理跨域前端处理跨域浏览器处理跨域 前端本地处理跨域:代理线上跨域的处理方式:Nginx反向代...

  • Nginx跨域

    Nginx解决跨域问题(CORS) CORS(Cross-Origin Resource Sharing) 跨域资...

  • ajax跨域--nginx反向代理

    用nginx反向代理实现跨域,是最简单的跨域方式。只需要修改nginx的配置即可解决跨域问题,支持所有浏览器,支持...

  • [mark]九种跨域方式实现原理

    前端如何使用proxyTable和nginx解决跨域问题 前言 前后端数据交互经常会碰到请求跨域,什么是跨域,以及...

  • nginx解决前端跨越详细方法

    nginx解决前端跨域 1、安装好nginx后,进入/usr/local/etc/nginx/nginx.conf...

  • nginx配置跨域请求

    转载 Nginx配置跨域请求 Access-Control-Allow-Origin 当出现403跨域错误的时候 ...

  • Nginx跨域请求设置

    Nginx跨域请求设置 开发环境中,前后端分离开发时,经常会有跨域请求的问题出现,Nginx可以设置如下: 说明:...

  • 配置Nginx后上传文件出现跨域问题

    问题详情:服务端已开启跨域,在配置Nginx反向代理后,使用ELMENT UI 反而出现跨域问题 Nginx监听9...

网友评论

      本文标题:nginx跨域

      本文链接:https://www.haomeiwen.com/subject/bdfgtctx.html