路由和Nginx
history路由前端router實(shí)現(xiàn)

history路由刷新頁(yè)面流程
一個(gè)新的請(qǐng)求發(fā)起后 --> 后端路由 -> 后端路由規(guī)則返回內(nèi)容 --> 瀏覽器加載頁(yè)面內(nèi)容 --> 前端路由處理渲染 -> 按前端路由規(guī)則修改頁(yè)面內(nèi)容 --> 結(jié)束
Nginx配置參考
server {
listen 80;
server_name <your-server-name>;
# http 轉(zhuǎn)成 https,配置了ssl證書(shū)時(shí)啟用
return 301 https://$host$request_uri;
# 解決history路由刷新問(wèn)題
location / {
# index.html文件在服務(wù)器中的存儲(chǔ)目錄
root /data/www; # /data/www需要修改為你服務(wù)器中的目錄
index index.html index.htm;
#資源訪問(wèn)失敗后定向到index.html
try_files $uri $uri/ /index.html;
}
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# SSL證書(shū)配置
server {
listen 443 ssl;
server_name <your-server-name>;
ssl_certificate <your_ssl_certificate_filepath>;
ssl_certificate_key <your_ssl_certificate_key_filepath>;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
# 解決http轉(zhuǎn)https后路由報(bào)錯(cuò)問(wèn)題
location / {
root /data/www;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}

浙公網(wǎng)安備 33010602011771號(hào)