Handle Google Verification files within NGinx Configuration

Published: 2018-09-11 14:19:42 +0000
Categories: NGinx,




When adding a site to Google's Webmaster tools (or analytics etc), they'll usually ask you to publish a verification file - and to leave it there.

I run a distributed edge, which means a request back to origin whenever Google decides to check my verification file is still there - not a massive overhead, but still feels wasteful. I handle select other resources at the edge too, so decided to have NGinx generate a response directly rather than fetching a file from origin

This snippet shows how to generate a HTTP 200 response and set the body content from with NGinx's configuration - you can do this for any file, but I'd only ever use it for very small static files personally


location /[verification filename] {
        return 200 '[file content]\n';

Usage Example

server {
    listen       80;
    server_name  www.example.invalid; 
    root /var/www/html;

    location /googleabcdef1234567890.html {
            return 200 'google-site-verification: googleabcdef1234567890.html\n';

    location / {

        # I'd actually proxy back to origin here, but to keep the example 
        # concise, look for the file on the filesystam
        try_files $uri $uri/ =404;





nginx, content, generate, HTTP,

Latest Posts

Remotely backing up PFsense Configuration (BASH)
FFMPEG: Converting RMVB to X264 MP4 (BASH)
Recursively print table (print_r equivalent) (LUA)
Bulk Delete Comments from (Self-Hosted) JIRA Issues (Misc)
Add a static entry to the ARP table (BASH)
SSL Cipher Hex codes to Human Readable Names (Misc)
Convert Ascii to Binary (BASH)
Intercepting Outbound DNS Queries (BASH)
Handle Google Verification files within NGinx Configuration (NGinx)
Getting WhatsApp Rich Snippet Previews Working (Misc)

Copyright © 2018 Ben Tasker | Sitemap | Privacy Policy
Available at snippets.bentasker.co.uk and snippets.6zdgh5a5e6zpchdz.onion