使用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的配置方法更好一点,项目定义路由时可以少一点麻烦
浙公网安备 33010602011771号