ngnix使用try_files命令进行history路由的适配

server {
listen 7860;
gzip on;
gzip_min_length 1k;
gzip_comp_level 9;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";

# 静态文件所在目录
root /usr/share/nginx/html/build;

location / {
try_files $uri $uri/ /index.html;
}

location /api {
# rewrite ^/api/(.*)$ /$1 break;
# api请求转发地址
proxy_pass http://172.16.2.144:7860;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
}

location /mass {
rewrite ^/mass/(.*)$ /$1 break;
# api请求转发地址
proxy_pass http://103.79.25.24:8880;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
}

location /health_check {
proxy_pass http://172.16.2.144:7860;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
}
}

posted on 2025-10-30 13:59  漫思  阅读(4)  评论(0)    收藏  举报

导航