1

According to this answer, the directive:

try_files $uri.html $uri/ =404;

Is supposed to make it so that

only one copy of the resource is served (that with no .html extension)

However, I have this directive in my config:

 server {
  listen 443 ssl default_server;
  listen [::]:443 ssl;

  server_name waynewerner.com www.waynewerner.com;

  ssl_certificate       /etc/letsencrypt/live/www.waynewerner.com/fullchain.pem;
  ssl_certificate_key   /etc/letsencrypt/live/www.waynewerner.com/privkey.pem;

  index index.html;
  root /var/www/waynewerner.com/site/;
  try_files $uri.html $uri/ =404;

  location ^~ /blog {
    alias /usr/share/blog/output;
    break;
  }

  location /.well-known {
    allow all;
    root /var/www/;
  }

  location /.hg {
    deny all;
    return 404;
  }
}

But you'll notice that you can go to both:

(At least that's how they appear in my Google Chrome address bar).

Is this something to worry about, or is Nginx doing the right thing?

Wayne Werner
  • 739
  • 4
  • 15
  • 27
  • What exactly is your goal here? Having multiple URLs serving same content is bad for SEO. – Tero Kilkanen Jan 25 '17 at 19:35
  • @TeroKilkanen the goal looks to be serving html files without the .html extension. Seems rather pointless to me personally. Installing Wordpress as most photographers do would be a good solution. With the try_files like that I'm surprised direct access to the html file works, I'd only have expected that if the try_files included $uri. In practice I don't think it'll matter so long as nothing links to the .html files so a crawler can't find it. However you've linked to it from this page so crawlers like Google can find it now. – Tim Jan 25 '17 at 19:46
  • @TeroKilkanen that's exactly what the linked answer (well, [this comment that produced that answer](http://serverfault.com/questions/346994/hide-html-file-extensions-using-nginx-rewrites/437124#comment371450_346999)) says. My understanding is that it would do some kind of *something*, I don't know, rewrite? redirect? The answer doesn't specify. Wordpress is right out for a [number of reasons](https://wpvulndb.com/) - this site is a statically generated site. Presumably I could setup a redirect with nginx, though that wasn't specified as necessary in the other answers, so... – Wayne Werner Jan 25 '17 at 21:15
  • either I'm wrong, or those comments/answers are. – Wayne Werner Jan 25 '17 at 21:15
  • What is the reason that you want to hide `.html` extension? – Tero Kilkanen Jan 25 '17 at 21:22
  • I agree that your server does not behave as the configuration file suggests. Are you sure that the server has been restarted since the configuration file was changed? Have you tested the configuration using `nginx -t`? BTW, I have tested the configuration and `.html` URIs return a 404 response as expected. – Richard Smith Jan 25 '17 at 23:00
  • double/triple checked. Syntax is OK, config reloaded (I use salt to manage my config). Just bashed my server over the head with hammer (i.e. fully stopped the server) and restarted. Used grep to make sure the line was there. And *still* it loads both .html and without. – Wayne Werner Jan 25 '17 at 23:16

0 Answers0