需求
- centos服务器,192.168.4.1
- docker安装了两个springboot服务:192.168.8.20:8080 192.168.8.21:8081
- 对外统一要用 192.168.4.1/xxx去访问所有的服务
案例1
server {
listen 80;
server_name localhost;
charset utf-8;
root /data/front;
# 这个目录是存放你的前端的代码的地方。
# 例如 在/data/front目录下 ,前端打包的结构是:
# /data/front/front_code
# front_code:
# css
# js
# index.html 等等
# 那么如下配置后,在页面中访问的路径主页的路径就是: 192.168.4.1/front_code
location /ss {
proxy_pass http://192.168.8.21:8081/ss;
}
}
案例2
server { listen 80; server_name localhost; charset utf-8; root /xxx; location /user { proxy_pass http://192.168.8.21:8080; } location /m1 { proxy_pass http://192.168.8.21:8080/user/m1; } location /m2 { proxy_pass http://192.168.8.21:8080/user/m2; } location /m3 { proxy_pass http://192.168.8.21:8080/user/m3; } }
案例3
server {
listen 80;
server_name localhost;
charset utf-8;
location /static { # /这个目录的请求都去往 /usr/share/nginx/html目录下找资源。
root /usr/share/nginx/html;
}
location / { #除了static的其他的 /这个请求都代理给后台服务
proxy_pass http://192.168.8.21:8080/user/m3;
}
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/214073.html原文链接:https://javaforall.net
