vue history nginx配置

增加: try_files $uri $uri/ @rewrites;

#工作模式及連接數上線
events {
worker_connections 1024; #單個工作進程 處理進程的最大併發數
}

http {
include mime.types;
default_type application/octet-stream;
#sendfile 指令指定 nginx 是否調用 sendfile 函數(zero copy 方式)來輸出文件,對於普通應用,
sendfile on;
#tcp_nopush on;

#keepalive_timeout  0;
keepalive_timeout  65;

# 開啓GZIP
gzip  on;

# # 監聽 80 端口,轉發請求到 3000 端口
server {
    #監聽端口
    listen      80;
    #編碼格式
    charset utf-8;

    # 前端靜態文件資源
    location / {
    root  /usr/src/app;
        index index.html index.htm;
        try_files $uri $uri/ @rewrites; 
    }
    # 配置如果匹配不到資源,將url指向 index.html, 在 vue-router 的 history 模式下使用,就不會顯示404
    location @rewrites {
        rewrite ^(.*)$ /index.html last;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章