使用docker运行了两个jar包镜像,端口号分别为8888,与9999,在nginx配置文件下分别配置如下

1.nginx默认监听80端口

2.8888端口采用了如下配置:

2.1 直接请求端口号为host:8888/server8888/entry/index (springboot 路由为/server8888/entry/index)

2.2 nginx配置文件如下:

location /server8888 {
  proxy_pass http://localhost:8888;
}

2.3 实际请求url为:host/server8888/entry/index

3.9999端口采用了如下配置:

3.1.直接请求端口号为host:9999/entry/index (springboot 路由为/entry/index)

3.2.nginx配置文件如下 

location /server9999 {
  rewrite ^/server9999/(.*) /$1 break;
  proxy_pass http://localhost:9999;
}

3.3 实际请求url为:host/server9999/entry/index?a=123

经测试,如果不带?后参数,host/server9999/entry/index会直接重定向到http://localhost:9999,是有问题的,需要解决

根据实际情况来说,9999的配置方法更好一点,项目定义路由时可以少一点麻烦

posted on 2020-07-19 17:20  lsz0210  阅读(742)  评论(0编辑  收藏  举报