如何配置nginx重定向到robots.txt&的网址sitemap.xml [英] How do i configure nginx to redirect to a url for robots.txt & sitemap.xml

查看:290
本文介绍了如何配置nginx重定向到robots.txt&的网址sitemap.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将nginx 0.6.32运行为benchdb的代理前端.我在数据库中有我的robots.txt,可以通过 http://www.example进行访问.com/prod/_design/mydesign/robots.txt .我也有在类似网址上动态生成的sitemap.xml.

I am running nginx 0.6.32 as a proxy front-end for couchdb. I have my robots.txt in the database, reachable as http://www.example.com/prod/_design/mydesign/robots.txt. I also have my sitemap.xml which is dynamically generated, on a similar url.

我尝试了以下配置:

server {
  listen 80;
  server_name example.com;
  location / {
  if ($request_method = DELETE) {
    return 444;
  }
  if ($request_uri ~* "^/robots.txt") {
    rewrite ^/robots.txt http://www.example.com/prod/_design/mydesign/robots.txt permanent;
  }

  proxy-pass http://localhost:5984;
  proxy_redirect off;
  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

这似乎可以用作重定向,但是有更简单的方法吗?

This appears to work as a redirect but is there a simpler way?

推荐答案

或者您也可以将其放在自己的位置-

Or you can put it simply in its own location -

location /robots.txt {
    alias /Directory-containing-robots-file/robots.txt;
} 

这篇关于如何配置nginx重定向到robots.txt&的网址sitemap.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆