worker_processes auto;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
  worker_connections 1024;
}

http {
  include /etc/nginx/mime.types;
  default_type application/octet-stream;

  access_log /var/log/nginx/access.log;

  sendfile on;
  keepalive_timeout 65;

  server {
    server_name uechi.io;
    listen 80;

    root /var/www/html;
    error_page 404 /404.html;

    location /404.html {
      internal;
    }

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

    location / {
      index index.html;
      try_files $uri $uri.html $uri/index.html @fallback;
    }

    location = / {
      if ($http_user_agent ~ curl) {
        rewrite / /TERMINAL last;
      }
    }
    
    location @fallback {
      root /var/www/html/_;
      try_files $uri $uri.html $uri/index.html =404;
    }
  }

  server {
    listen 80;
    server_name www.uechi.io;
    return 301 $scheme://uechi.io$request_uri;
  }
}