解決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;
    }
}

即可

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM