我創建了 2 個單獨的 robots.txt 檔案:robots.txt和disabled-robots.txt
我的 nginx 配置中有一個帶有別名的服務器塊。我想要實作的是:
- example.com/robots.txt => robots.txt
- v2.example.com/robots.txt => disabled-robots.txt
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name v2.example.com example.com;
location = /robots.txt {
// I think I need to update here, but confused about what I should put
// if ($host == v2.example.com) {
// show disabled-robots.txt
// } else {
// show robots.txt
// }
}
}
我在 StackOverflow 上找到的所有示例都顯示了 2 個單獨的服務器塊,但是我想保留我的一個服務器塊。
uj5u.com熱心網友回復:
不要使用if內部 a location(在這種情況下有問題),而是使用 a mapwith try_files。
例如:
map $host $which_robot {
default /robots.txt;
v2.example.com /disabled-robots.txt;
}
server {
...
location = /robots.txt {
root /path/to/directory;
try_files $which_robot =404;
}
}
注意map必須在server塊外宣告。請參閱地圖檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/526435.html
標籤:nginx机器人.txt
上一篇:帶有“useBreadcrumbsfromuse-react-router-breadcrumbs”的唯一鍵道具問題
