Nginx有兩種配置靜態路徑檔案的方法:
1,root配置
location / {
root /var/app_secrecy/resources/templates; //靜態檔案的在服務器路徑
}
需要注意,使用root配置是,如果需要加前綴URI情況下,如:
location /app/ {
root /var/app_secrecy/resources/templates;
}
訪問的地址:http://xxxx/app/a.html
其訪問的路徑: /var/app_secrecy/resources/templates/app/a.html
有可能引起404問題,
2,alias配置
針對有前綴URI的靜態html需求,建議使用alias配置,
location ^~/app/ {
alias /var/app_secrecy/resources/templates/;
}
訪問地址:http://xxxx/app/a.html
其訪問的路徑:/var/app_secrecy/resources/templates/a.html
需要注意:在alias配置時,alias配置目錄名必須包含"/",
3,總結
root配置:配置路徑+完整的訪問路徑(完整的location前綴+靜態檔案);
alias配置:配置路徑+靜態檔案(去掉location的URI前綴);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/357268.html
標籤:其他
上一篇:行業務實派:解鎖資料價值,翼方健數全堆疊隱私安全計算技術
下一篇:Nginx+Tomcat發布WebService soap:address location https 變為 http問題處理
