nginx 的几种用法
2021-11-13 本文已影响0人
嗚嗚雲
1、反向代理
server {
listen 80;
server_name test.com;
location / {
proxy_pass http://172.10.110.100:8080;
proxy_set_header Host $host;
}
}
2、springboot + vue 反向代理
# 支持 websocket 设置一个变量
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream test_prod {
fair;
server 192.168.1.101:24035;
server 192.168.1.102:24035;
}
# 域名跳转
server {
listen 80;
server_name test.cn;
rewrite "^/(.*)$" http://test.com/$1;
}
# 正向代理 test.com
server {
listen 80;
server_name test.com;
access_log /export/servers/nginx/logs/test.com_access.log;
error_log /export/servers/nginx/logs/test.com_error.log;
# vue 静态资源走本地
location / {
root /home/admin/apps/appName/dist/;
index index.html;
}
# 图片资源走图片服务,这里仅仅是域名替换
location ~ ^/(image)/\.* {
rewrite ^/(.*) /$1 break;
proxy_pass http://image.com;
}
# 后端服务的uri前缀是v1的走后端服务
location ~^/(v1) {
proxy_pass http://test_prod;
proxy_set_header Host $host;
# 支持 websoket 使用变量
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}