nginx路由分派
打开nginx.conf文件,添加server
server { listen 888; # 监听的端口 server_name localhost; # 域名或者ip location ~ (^/gwzj).* { //匹配接口正则 proxy_pass http://172.16.50.20:888; # 接口匹配到上列正则格式后会分派到该地址 proxy_set_header Host $host:$server_port; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Port $server_port; } location ~ (^/api).* { proxy_pass http://172.16.50.18:9002; proxy_set_header Host $host:$server_port; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Port $server_port; } location / { proxy_pass http://172.16.50.20:8095; proxy_set_header Host $host:$server_port; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Port $server_port; } } server { listen 8888; server_name http://192.168.16.88; location ~ (^/ybzf).* { proxy_pass http://172.16.50.20:8888; proxy_set_header Host $host:$server_port; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Port $server_port; } location ~ (^/api).* { proxy_pass http://172.16.50.18:9002; proxy_set_header Host $host:$server_port; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Port $server_port; } location / { proxy_pass http://172.16.50.20:8097; proxy_set_header Host $host:$server_port; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Port $server_port; } }
小白技术分享