0

To perform domain verification for google, I must serve a file at the root of my domain. The filename is typically googleXXXXXXXXXXXXX.html (those Xs are a hex substring).

So I copied it to my site's root (/var/www/html/), and edited nginx's config like this:

location ~* /google.+\.html$ {
  alias /var/www/html/$1;
}    

Though I get a 404. I didn't hardcode the filename, but it fails even if I do.


Please note I know of this widely-used trick:

location = /googleXXXXX.html {
  rewrite ^/(.*) $1;
  return 200 "google-site-verification: $uri";
}

But I don't want to do that because it's not future proof - I want to serve the file as is.

| improve this question | | | | |
  • Where have you placed the file? Is it in /var/www/html? – Richard Smith Nov 12 '19 at 13:23
  • @RichardSmith Yes, in the root. Which for me is /var/www/html/. – lonix Nov 12 '19 at 13:24
  • Are other files in the root being served correctly? Why do you need a special location for this one file? – Richard Smith Nov 12 '19 at 14:18
  • @RichardSmith That's just how google wants it. BTW I figured it out and added my answer below. Since you're the resident nginx expert, do you know why it works but my original code didn't? I'm glad to get it working, but I don't understand why it works! :-) – lonix Nov 12 '19 at 16:12
0

Unsure why alias didn't work, but this works for me:

location ~* /google.+\.html$ {
  try_files $uri =404;
}
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.