我正在嘗試在此處的檔案之后為 index.html 檔案添加特殊標頭:http: //nginx.org/en/docs/http/ngx_http_core_module.html#location。我想X-foo: index在沒有任何路徑的情況下提供請求,即使用/.
我使用“=”修飾符并首先嘗試使用此配置:
events {}
http {
server {
listen 80;
root /tmp/web;
index index.html;
location = / {
add_header X-foo "index";
}
location / {
add_header X-foo "other";
}
}
}
問題是,我得到X-foo: other了/和/foo.html。如果我return 200在第一個位置塊內放置一個,我會得到X-foo: index標題但沒有任何內容。
現在,如果我index.html在路徑中指定并指定如下配置:
location = /index.html {
add_header X-foo "index";
}
我得到X-foo: index了/請求。似乎在接收到/nginx 時正在將請求重新路由到內部/index.html。我的理解是否正確,或者在使用“=”修飾符時我遺漏了什么?
uj5u.com熱心網友回復:
這正是 Nginx 所做的。
index模塊在內部重寫 URI from /to/index.html然后重新開始搜索匹配location以處理請求。
最終處理請求的是提供內容的那個,而location不是接收初始請求的那個。add_headerlocation
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/487223.html
