vueRouter history模式下 nginx配置

對於VUE的router[mode: history]模式(這裏主要是爲了去除連接上的"#")
開發的時候,通常都不出問題。是由於開發時用的服務器爲node,Dev環境中已配置好了,html

nginx運行的時首頁沒有問題,連接也沒有問題,但在點擊刷新後,頁面就會顯示(404)node

原配置:nginx

location / {
        root  /home/testhadoop/www/html;
        index index.html index.htm;
    }

解決方案以下:bash

方案一:
使用try_files服務器

語法:try_files file1 [file2 ... filen] fallbackoop

location / {
    root  /home/testhadoop/www/html;
    index index.html index.htm;
    try_files $uri $uri/ /index.html;
}

方案二:
使用try_filescode

location /{

    root  /home/testhadoop/www/html;
    index  index.html index.htm;

    if (!-e $request_filename) {
        rewrite ^/(.*) /index.html last;
        break;
    }
}

方案三:
使用error_page (通常不建議用, 404的方式會被第三方劫持)router




  

原文:https://www.jianshu.com/p/f7a19f1bafa0location /{ root /home/testhadoop/www/html; index index.html index.htm; error_page 404 /index.html; }
相關文章
相關標籤/搜索