  server {
    listen 80; 
    listen 443 ssl;
    ssl_certificate     /etc/nginx/certs/neocities.org.crt;
    ssl_certificate_key /etc/nginx/certs/neocities.org.key;
    server_name www.neocities.org;
    rewrite ^(.*)$ $scheme://neocities.org$1 permanent;
  }

  server {
    listen 80; 
    listen 443 ssl;
    ssl_certificate     /etc/nginx/certs/neocities.org.crt;
    ssl_certificate_key /etc/nginx/certs/neocities.org.key;

    set $ssl off;
    if ($scheme = https) {
      set $ssl on; 
    }   

    root /home/web/neocities-web/public;
    server_name neocities.org;
    access_log /var/log/nginx/neocities-web.log;

    error_page 500 = /gateway_error.html;

#    location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
#      expires 60s;
#      log_not_found off;
#    }   

    try_files $uri @neocities;

    location @neocities {
      proxy_set_header  X-Real-IP  $remote_addr;
      proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-Forwarded-Ssl $ssl;
      proxy_max_temp_file_size 0;

      # proxy_pass http://127.0.0.1:20000;
      proxy_pass http://unix:/var/run/neocities/neocities.sock;
      break;
    }
  }

  server {
    listen 80;
    listen 443 ssl;
    ssl_certificate     /etc/nginx/certs/neocities.org.crt;
    ssl_certificate_key /etc/nginx/certs/neocities.org.key;

    server_name ~^(?<subdomain>.+)\.neocities.org$;
    access_log /var/log/nginx/neocities-sites.log neocities;
    root /home/web/neocities-web/public/sites/$subdomain;
    index /index.html;

    error_page 404 = @notfound;

    location @notfound {
        try_files /not_found.html @notfound_root;
    }

    location @notfound_root {
      root /home/web/neocities-web/public;
      try_files /web_site_not_found.html =404;
    }

    location ~*  \.(html|jpg|jpeg|png|gif|ico|css|js)$ {
      # expires 20s;
      log_not_found off;
    }
  }
