nginx反向代理解決跨域問題

1、反向代理原理

2、nginx.conf配置文件,

server {
        listen       8088;//端口
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        #root   html;
        #index  index.html index.htm;
        

        location / {
            add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
            add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
            if ($request_method = 'OPTIONS') {
                return 204;
            }
            proxy_pass   指向的ip;
        }

}

參考:https://www.cnblogs.com/taiyonghai/p/9402734.html

            https://segmentfault.com/a/1190000012550346

            http://nginx.org/en/download.html

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章