
我們的 nginx 設定檔中有很多站點,我們希望使用自訂的 error_page,但所有站點都使用相同的 error_page。
我嘗試在 http{} 中將其設定為 /path/to/my/404.html。我注意到它看起來在“根”目錄中(所以/path/to/my/root/path/to/my/404.html)
有沒有一種方法可以讓我的所有虛擬主機使用一個 404 文件,而無需在每個目錄中對文件進行符號連結?
答案1
將 Alias 指令新增至該位置:
location /404.html {
alias /shared/files/404.html
}
error_page 404 /404.html
應該可以做到這一點。