大家好,又见面了,我是你们的朋友全栈君。
nginx配置多个server
server {
listen 80;
server_name localhost;
root C:\Users\Administrator\Desktop\dist;
location / {
try_files $uri /index.html;
}
location /api/ {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1:8086/uaapi/;
proxy_send_timeout 300;
proxy_read_timeout 300;
proxy_connect_timeout 300;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 8383;
server_name localhost;
root F:\QC-HTML\QC-HTML\qc-html\dist;
location / {
try_files $uri /index.html;
}
location /api/ {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1:8484/api/;
proxy_send_timeout 300;
proxy_read_timeout 300;
proxy_connect_timeout 300;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
一个server多个location
server {
listen 8989;
server_name localhost;
access_log logs/esb.log;
error_log logs/esb-error.log;
#将所有请求转发给 esb 的应用处理
location = /uaapi {
proxy_buffer_size 128k;
proxy_buffers 32 32k;
proxy_busy_buffers_size 128k;
proxy_pass http://192.168.31.83:8086/uaapi/addressManage/getAddressByDept?dept=5019;
}
location /uaapi/dc {
proxy_buffer_size 128k;
proxy_buffers 32 32k;
proxy_busy_buffers_size 128k;
proxy_pass http://127.0.0.1:8086;
}
location /dd {
proxy_buffer_size 128k;
proxy_buffers 32 32k;
proxy_busy_buffers_size 128k;
proxy_pass http://127.0.0.1:8086/uaapi/dc/addressManage/getAddressByDept?dept=5019;
}
}
location 拦截不会区分大小写
location = /uaapi {
}
请求路径只能写127.0.0.1:8989/uaapi
location /uaapi/dc {
proxy_buffer_size 128k;
proxy_buffers 32 32k;
proxy_busy_buffers_size 128k;
proxy_pass http://127.0.0.1:8086;
}
请求路径写127.0.0.1:8989/uaapi/dc/xxx
nginx实际转发路径:127.0.0.1:8086/uaapi/dc/xxx
location /dd {
proxy_buffer_size 128k;
proxy_buffers 32 32k;
proxy_busy_buffers_size 128k;
proxy_pass http://127.0.0.1:8086/uaapi/dc/addressManage/getAddressByDept?dept=5019;
}
请求路径写127.0.0.1:8989/ddxxx
nginx实际转发路径:127.0.0.1:8086/uaapi/dc/addressManage/getAddressByDept?dept=5019xxx
会带上后面的xxx
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/125072.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...