18.商品业务-nginx

1 搭建域名访问

image-20220505140955465

image-20220505141244578

1.1 修改hosts

添加域名映射:

192.168.56.10 gulimall.com

注意关闭ip代理软件,否则修改hosts不生效,浏览器会优先考虑代理工具(如添加 pac 文件、SwitchySharp等)的代理,建议调试的时候先关闭这些代理。

1.2 配置nginx

1、进入linux目录/mydata/nginx/conf/conf.d

2、复制一份default.conf,cp default.conf gulimall.conf

3、修改gulimall.conf里的配置

server_name  gulimall.com;

proxy_pass http://192.168.56.1:10000;

image-20220505144751160

4、保存退出后重启nginx,docker restart nginx

5、访问http://gulimall.com/测试

2 配置nginx负载均衡

1、修改nginx.conf

upstream gulimall{
    server 192.168.56.1:88;
}

image-20220505150633790

2、修改gulimall.conf

nginx转发请求时会丢失Host,需要手动添加

location / {
   proxy_set_header Host $host;
   proxy_pass http://gulimall;
}

3、重启nginx

4、配置网关,路由规则放到最后,重启服务

- id: gulimall_host_route
  uri: lb://gulimall-product
  predicates:
    - Host=**.gulimall.com,gulimall.com

5、测试

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值