#{"rootDirectory":"","phpVersion":"7.4"}
server {
  listen 80;
  listen [::]:80;
  listen 443 quic;
  listen 443 ssl;
  listen [::]:443 quic;
  listen [::]:443 ssl;
  http2 on;
  http3 off;
  {{ssl_certificate_key}}
  {{ssl_certificate}}
  {{server_name}}
  {{root}}

  {{nginx_access_log}}
  {{nginx_error_log}}

  if ($scheme != "https") {
    rewrite ^ https://$host$request_uri permanent;
  }

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

  {{settings}}

  include /etc/nginx/global_settings;

  try_files $uri $uri/ /index.php?$args;
  index index.php index.html;

  location / {
    error_page 404 /index.php?$query_string;
    try_files $uri $uri/ /index.php?$query_string;
  }

  location ~ /announcements/?(.*)$ {
    rewrite ^/(.*)$ /hosting/index.php?rp=/announcements/$1;
  }

  location ~ /download/?(.*)$ {
    rewrite ^/(.*)$ /hosting/index.php?rp=/download$1;
  }

  location ~ /knowledgebase/?(.*)$ {
    rewrite ^/(.*)$ /hosting/index.php?rp=/knowledgebase/$1;
  }

  location ~ /store/ssl-certificates/?(.*)$ {
    rewrite ^/(.*)$ /hosting/index.php?rp=/store/ssl-certificates/$1;
  }

  location ~ /store/sitelock/?(.*)$ {
    rewrite ^/(.*)$ /hosting/index.php?rp=/store/sitelock/$1;
  }

  location ~ /store/website-builder/?(.*)$ {
    rewrite ^/(.*)$ /hosting/index.php?rp=/store/website-builder/$1;
  }

  location ~ /store/order/?(.*)$ {
    rewrite ^/(.*)$ /hosting/index.php?rp=/store/order/$1;
  }

  location ~ /hosting/cart/domain/renew/?(.*)$ {
    rewrite ^/(.*)$ /hosting/index.php?rp=/cart/domain/renew$1;
  }

  location ~ /account/paymentmethods/?(.*)$ {
    rewrite ^/(.*)$ /hosting/index.php?rp=/account/paymentmethods$1;
  }

  location ~ /password/reset/?(.*)$ {
    rewrite ^/(.*)$ /hosting/index.php?rp=/password/reset/$1;
  }

  location ~ /account/security/?(.*)$ {
    rewrite ^/(.*)$ /hosting/index.php?rp=/account/security$1;
  }

  location ~ /subscription?(.*)$ {
    rewrite ^/(.*)$ /hosting/index.php?rp=/subscription$1;
  }

  location ~ /auth/provider/google_signin/finalize/?(.*)$ {
    rewrite ^/(.*)$ /hosting/index.php?rp=auth/provider/google_signin/finalize$1;
  }

  location ~ /admin/(addons|apps|search|domains|help\/license|services|setup|utilities\/system\/php-compat)(.*) {
    rewrite ^/(.*)$ /hosting/admin/index.php?rp=/admin/$1$2 last;
  }

  location ~ /admin/client/?(.*)/paymethods/?(.*)$ {
    rewrite ^/(.*)$ /hosting/admin/index.php?rp=/client/?(.*)/paymethods/$1;
  }

  location ~ /admin/setup/auth/?(.*)$ {
    rewrite ^/(.*)$ /hosting/admin/index.php?rp=/setup/auth/$1;
  }

  location ~ /admin/client/?(.*)/tickets/?(.*)$ {
    rewrite ^/(.*)$ /hosting/admin/index.php?rp=/client/?(.*)/tickets/$1;
  }

  location ~ /admin/client/?(.*)/invoice/?(.*)/capture/?(.*)$ {
    rewrite ^/(.*)$ /hosting/admin/index.php?rp=/client/?(.*)/invoice/?(.*)/capture/$1;
  }

  location ~ /admin/account/security/two-factor/?(.*)$ {
    rewrite ^/(.*)$ /hosting/admin/index.php?rp=/admin/account/security/two-factor/$1;
  }

  location ~ /admin/search/intellisearch?(.*)$ {
    rewrite ^/(.*)$ /hosting/admin/index.php?rp=/search/intellisearch/$1;
  }

  location ^~ /vendor/ {
    deny all;
    return 403;
  } 

  location ~ \.php$ {
    include fastcgi_params;
    fastcgi_intercept_errors on;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    try_files $uri =404;
    fastcgi_read_timeout 3600;
    fastcgi_send_timeout 3600;
    fastcgi_param HTTPS $fastcgi_https;
    fastcgi_pass 127.0.0.1:{{php_fpm_port}};
    fastcgi_param PHP_VALUE "{{php_settings}}";
  }

  location ~* ^.+\.(css|js|jpg|jpeg|gif|png|ico|gz|svg|svgz|ttf|otf|woff|woff2|eot|mp4|ogg|ogv|webm|webp|zip|swf)$ {
    add_header Access-Control-Allow-Origin "*";
    add_header alt-svc 'h3=":443"; ma=86400';
    expires max;
    access_log off;
  }

  if (-f $request_filename) {
    break;
  }
}