首页 > 其他 > 详细

nginx跨域

时间:2020-02-03 17:13:24      阅读:64      评论:0      收藏:0      [点我收藏+]

https://blog.csdn.net/weixin_33716941/article/details/94304728

1. nginx.conf

   

upstream jianshubao-rd {
    server 192.168.0.102:8082;
    }
upstream jianshubao-fe {
    server 192.168.0.103:8080;
    }
server {
        listen       80;
        server_name  fe.max.com;
 
        location / {
            proxy_pass   http://jianshubao-fe;
            index  index.html index.htm;
        }
        location /fe {
            rewrite ^.+fe/?(.*)$ /$1 break;
            #proxy_pass   http://jianshubao-fe;
            proxy_pass   http://localhost:82;
            index  index.html index.htm;
        }    
 
 
    }
server {
        listen       82;
        server_name  rd.max.com;
 
            location / {
            proxy_pass   http://jianshubao-rd;
            index  index.html index.htm;
            }
        }

反向代理的职责就是用户不知道访问的是哪台服务器

通过监听80端口,将/fe后缀的请求重定向到本地的82端口
通过upstream定义 让两台主机的server重定向到一台主机的80端口 和82端口上
进而实现前后端分离,前后端又在一个域下面
但是这样使用起来产生了一个新的问题,前端ajax请求后端的时候响应速度慢了很多。
有可能是 百兆网卡的问题,还有可能是配置的不是很完满。
不过先实现再优化是我们的开发原则。

nginx跨域

原文:https://www.cnblogs.com/sjzxxy/p/12256229.html

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