wordbotch.com

Blog


nginx configuration

I finally worked out the simplest way to configure NginX to redirect everything to a single 'canonical' domain. Previously I had it kind of working, but it was a bit hacky and I didn't really understand it. Now it's way better.

Took me a while to realise that the order of the server entries in the config file matters. The important part is that the default server comes last and matches all hosts. Any request that hasn't already been matched gets redirected by the default. This includes all http traffic (redirected to https), as well as alternative domains.


server {
  listen 443 ssl;

  root /var/www/;
  index index.php index.html index.htm;

  server_name wordbotch.com;

  include snippets/ssl-wordbotch.conf;
  include snippets/ssl-params.conf;

  location ~ /.well-known {
    allow all;
  }
  ...
}

server {
  listen 80 default_server;
  listen 443 default_server;
  server_name _;

  include snippets/ssl-wordbotch.conf;
  include snippets/ssl-params.conf;

  return 301 https://wordbotch.com;
}