Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i configure nginx to redirect to a url for robots.txt & sitemap.xml

Tags:

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.

I have tried the following config:

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?

like image 665
timbo Avatar asked Jul 07 '09 07:07

timbo


People also ask

How do I redirect http to https in NGINX?

Redirect HTTP to HTTPS version for Specified domain in Nginx Server_name domain-name.com www.domain-name.com – it specifies the domain names. So, replace it with your website domain name that you want to redirect. Return 301 https://domain-name.com$request_uri – it moves the traffic to the HTTPS version of the site.

What is return 301 in NGINX?

Temporary and Permanent Nginx Redirect Explained To map this change, the redirects response code 301 is used for designating the permanent movement of a page. These kinds of redirects are helpful when the user wants to change the domain name and no longer wants a browser to access it.


1 Answers

Or you can put it simply in its own location -

location /robots.txt {     alias /Directory-containing-robots-file/robots.txt; }  
like image 59
PlanetUnknown Avatar answered Sep 21 '22 09:09

PlanetUnknown