Skip to content

Instantly share code, notes, and snippets.

@MaxLazar
Last active March 25, 2024 07:55
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaxLazar/80520b499c40ec71fde55ae69b11c474 to your computer and use it in GitHub Desktop.
Save MaxLazar/80520b499c40ec71fde55ae69b11c474 to your computer and use it in GitHub Desktop.
Serve robots.txt inline in Nginx
Serve robots.txt inline in Nginx
06/18/2015 nginx 3 Comments
To quickly serve a robots.txt from Nginx without actually having access to the physical file you can define the content of the robots.txt file in the Nginx .conf file.
Allow access to all User-agents:
location /robots.txt {return 200 "User-agent: *\nDisallow:\n";}
Disallow access to every User-agent:
location /robots.txt {return 200 "User-agent: *\nDisallow: /\n";}
@david-crowdstreet
Copy link

david-crowdstreet commented Oct 31, 2017

Typo on line 7: Change Disallow to Allow

Also can be done on multiple lines:

    location /robots.txt {
        allow all;
        access_log off;
        log_not_found off;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment