server {
  server_name www.kensaku.online kensaku.online;

  if ($host = www.kensaku.online) {
    return 301 https://kensaku.online$request_uri;
  }

  root  /www/active/kensaku.online/www;
  index index.php;

  add_header Permissions-Policy interest-cohort=();
  add_header X-Content-Type-Options nosniff;
  #add_header X-Frame-Options SAMEORIGIN;
  add_header X-XSS-Protection "1; mode=block";
  add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains; preload';

  rewrite ^(/.+)\.php$ https://$host$1 permanent;

  location / {
    add_header Permissions-Policy interest-cohort=();
    add_header X-Content-Type-Options nosniff;
    #add_header X-Frame-Options SAMEORIGIN;
    add_header X-XSS-Protection "1; mode=block";
    add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains; preload';
    satisfy any;
    allow all;
    rewrite ^(.*)$ /$1.php;
    try_files $uri $uri/ /index.php?$query_string;
  }

  location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }

  location ~*  \.(jpg|jpeg|png|gif|ico|woff|webp)$ {
    expires 365d;
  }

  location ~*  \.(css|js|json)$ {
    expires 7d;
  }

  listen 443 ssl http2;
  ssl_certificate /etc/letsencrypt/live/kensaku.online/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/kensaku.online/privkey.pem;
  include /etc/letsencrypt/options-ssl-nginx.conf;
}

server {
  server_name www.kensaku.online kensaku.online;
  listen 80;

  if ($host = kensaku.online) {
    return 301 https://$host$request_uri;
  }

  if ($host = www.kensaku.online) {
    return 301 https://$host$request_uri;
  }

  return 404;
}
