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
今天的文章Nginx配置多个server_nginx启动命令和停止命令「建议收藏」分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/77910.html