Aristotle
发布于 2023-03-23 / 4 阅读 / 0 评论 / 0 点赞

nginx的单页面server的配置和rewrite指令的使用

nginx的单页面server的配置和rewrite指令的使用

Nginx rewrite 总结:参考:https://www.jianshu.com/p/a1fce9358d44

server {
    listen 81;
    root /home/xxx/wwwdev/orgadmin/dist;
    index index.html;
    client_max_body_size 200M;
    client_body_buffer_size 128K;

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

    location @router {
        rewrite ^.*$ /index.html last;
    }

    location /dev-api {
        rewrite ^/dev-api/(.*)$ /$1 break;
        proxy_pass http://127.0.0.1:8202;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host $http_host;
        proxy_set_header X-Forwarded-Port $server_port;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}