小陆同学

python 中文名:蟒蛇,设计者:Guido van Rossum

导航

解决nginx+vue--502的问题

当前的nginx配置如下:

server {
    listen       80;
    server_name  localhost;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
    location @router{
        rewrite ^(.+)$ /index.html last;
    }
}

遇到的问题是,当访问 http://localhost:80的时候是可以的,但访问除此之外的其他路由时遇到了502的问题

解决方案:+ try_files

server {
    listen       80;
    server_name  localhost;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        try_files $uri $uri/ @router;
    }
    location @router{
        rewrite ^(.+)$ /index.html last;
    }
}

即可

 

posted on 2022-04-20 20:20  小陆同学  阅读(1288)  评论(0编辑  收藏  举报