nginx分享代理本地的两个服务
本地启动了两个项目,spring-cloud,前后端分离的
配置nginx如下:
server {
# 服务一绑定了80,所以需要绑定888
listen 888;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
# 直接访问服务一
location / {
proxy_pass http://localhost:80;
proxy_set_header Host $proxy_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# 服务一的后端代理
location ^~ /dev-api {
proxy_pass http://localhost:80;
proxy_set_header Host $proxy_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# 服务一的模块代理
location ^~ /waterway-report {
proxy_pass http://localhost:8888/waterway-report;
proxy_set_header Host $proxy_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# 服务二的路径
location ^~ /map {
proxy_pass http://localhost:9521/map;
proxy_set_header Host $proxy_host/map;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# 服务二的后端api
location ^~ /x_api {
proxy_pass http://localhost:9521/x_api;
proxy_set_header Host $proxy_host/map;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}