首页 > 其他 > 详细

Nginx解决跨域问题

时间:2020-02-10 19:12:26      阅读:48      评论:0      收藏:0      [点我收藏+]

如果在b工程的页面直接发送ajax请求a时会发生跨域问题,那么解决方案为:将A和B同时代理到Nginx,由Nginx做请求路由,直接在B工程页面中直接访问Nginx即可
          

 server {
                listen       80;
                server_name  www.chx.com;

                #charset koi8-r;

                #access_log  logs/host.access.log  main;

                location /a {
                    #proxy_connect_timeout 1;
                    #proxy_send_timeout 1;
                    #proxy_read_timeout 1;
                    proxy_pass http://www.a.com:8080/a/;
                    index index.html index.htm;
                    
              }
            location /b {
                    #proxy_connect_timeout 1;
                    #proxy_send_timeout 1;
                    #proxy_read_timeout 1;
                    proxy_pass http://www.b.com:8081/b/;
                    index index.html index.htm;
                }
            }

B工程页面请求:

$("#button").click(function () {
                    $.ajax({
                        url:"http://www.chx.com/a/AServlet?username="+$("#username").val(),
                        type:"GET",
                        success:function (result) {
                            alert(result);
                        }
                    })
                });

 

直接在B工程访问Nginx,由Nginx在内部做转发,以解决跨域问题

 

Nginx解决跨域问题

原文:https://www.cnblogs.com/chx9832/p/12291755.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!