我正在NGINX后面运行Kibana,我想添加robots.txt。我将robots.txt添加到了/var/www/example.com,但是无论我尝试什么,当我访问example.com/robots.txt时,它都会重定向到Kibana。
server {
server_name example.com www.example.com;
location = /robots.txt {
root /var/www/example.com/;
}
location / {
if ($request_uri ~* "^/robots.txt") {
rewrite ^/robots.txt /robots.txt last;
}
proxy_pass http://localhost:5601;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
~
}
server {
if ($host = www.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name example.com www.example.com;
return 404; # managed by Certbot
}
我尝试了以下操作:
root /var/www/example.com/html;
在位置/
下location = /robots.txt {
alias /var/www/example/com/html/robots.txt ;
}
在服务器下。
我能找到的最接近的是根目录,它会将example.com/robots.txt重定向到example.com/var/www/example.com/html/robots.txt。
答案 0 :(得分:1)
如果/robots.txt
的路径是/var/www/example.com/html/robots.txt
,请使用:
server {
...
location = /robots.txt {
root /var/www/example.com/html;
}
location / {
...
}
}
完全匹配location
块始终优先。有关详细信息,请参见this document。