[NGINX]可以';t让proxy_pass和robots.txt正常工作
我在NGINX后面运行Kibana,我想添加一个robots.txt。我将robots.txt添加到/var/www/example.com,但无论我尝试什么,当我访问example.com/robots.txt时,它都会重定向到Kibana[NGINX]可以';t让proxy_pass和robots.txt正常工作,nginx,robots.txt,Nginx,Robots.txt,我在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
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。如果
/robots.txt
的路径是/var/www/example.com/html/robots.txt
,请使用:
server {
...
location = /robots.txt {
root /var/www/example.com/html;
}
location / {
...
}
}
精确匹配的
位置
块将始终优先。有关详细信息,请参见。是/var/www/example/com/html/robots.txt
或/var/www/example/com/robots.txt
或/var/www/example.com/html/robots.txt
上的文件吗?服务器上的完整路径是/var/www/example.com/html/robots.txt
。谢谢,这很有效。还感谢您提供文档链接,这也澄清了一些问题。我以前没有找到那一页。