
我在理解 Nginx 中的路由處理時遇到了問題。
server {
listen 80;
listen [::]:80;
server_name my_domain;
root /var/www/ep;
index index.html;
error_page 403 404 /my403.html;
location /images/ {
try_files $uri @not_found;
}
location @not_found {
root /var/www/ep/not_found;
try_files NON_EXISTENT_1 /not_found.jpg;
}
}
對於上面的配置,當我訪問http://my_domain/images/xyz.png或者http://my_domain/images/我希望@not_found
位置指令發生,從/var/www/ep/not_found/not_found.jpg
(它存在)返回圖像,但不知何故/var/www/ep/not_found.jpg
正在嘗試路徑(它不存在)。它導致顯示/my403.html
文件。
我想使用命名位置方法(@not_found
)。
有人能解釋一下這裡發生了什麼事嗎?
為什麼/var/www/ep/not_found/not_found.jpg
不送達?