+server {
+ listen 80;
+ server_name {{ domain }} www.{{ domain }};
+ include snippets/letsencrypt.conf;
+ location / {
+ return 301 https://{{ domain }}$request_uri; # enforce https
+ }
+}
+server {
+ listen 443 ssl;
+ http2 on;
+ ssl_certificate /etc/letsencrypt/live/{{ domain }}/fullchain.pem;
+ ssl_certificate_key /etc/letsencrypt/live/{{ domain }}/privkey.pem;
+# ssl_certificate /etc/ssl/certs/{{ domain }}.pem;
+# ssl_certificate_key /etc/ssl/private/{{ domain }}.key;
+
+ server_name {{ domain }};
+ location / {
+ return 301 https://www.{{ domain }}$request_uri;
+ }
+}
+server {
+ listen 443 ssl;
+ http2 on;
+ ssl_certificate /etc/letsencrypt/live/{{ domain }}/fullchain.pem;
+ ssl_certificate_key /etc/letsencrypt/live/{{ domain }}/privkey.pem;
+# ssl_certificate /etc/ssl/certs/{{ domain }}.pem;
+# ssl_certificate_key /etc/ssl/private/{{ domain }}.key;
+
+ server_name www.{{ domain }};
+ root /srv/www/{{ domain }}/;
+
+
+ access_log /var/log/nginx/a_{{ shortname }}.log;
+ error_log /var/log/nginx/e_{{ shortname }}.log;
+
+ index index.php;
+ client_max_body_size 1G;
+ autoindex on;
+
+ # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
+ # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
+
+ location ^~ /.well-known {
+ allow all;
+ if ($request_method = 'OPTIONS') {
+ add_header 'Access-Control-Allow-Origin' '*';
+ add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
+ add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
+ add_header 'Access-Control-Max-Age' 1728000;
+ add_header 'Content-Type' 'text/plain; charset=utf-8';
+ add_header 'Content-Length' 0;
+ return 204;
+ }
+ if ($request_method = 'POST') {
+ add_header 'Access-Control-Allow-Origin' '*' always;
+ add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
+ add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
+ add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
+ }
+ if ($request_method = 'GET') {
+ add_header 'Access-Control-Allow-Origin' '*' always;
+ add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
+ add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
+ add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
+ }
+
+ }
+ #location ~ /\. {
+ # deny all;
+ #}
+
+
+ # Deny access to any files with a .php extension in the uploads directory
+ # Works in sub-directory installs and also in multisite network
+ # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
+ location ~* /(?:uploads|files)/.*\.php$ {
+ deny all;
+ }
+
+ location = /favicon.ico {
+ log_not_found off;
+ access_log off;
+ }
+
+ location = /robots.txt {
+ allow all;
+ log_not_found off;
+ access_log off;
+ }
+
+ location / {
+ # This is cool because no php is touched for static content.
+ # include the "?$args" part so non-default permalinks doesn't break when using query string
+ try_files $uri $uri/ /index.php?$args;
+ }
+
+ location ~ \.php$ {
+ #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
+ include fastcgi.conf;
+ fastcgi_intercept_errors on;
+ fastcgi_pass unix:/var/run/php/php{{ php_version }}-fpm.sock;
+ fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
+ fastcgi_param HTTPS $fastcgi_https;
+ fastcgi_param HTTP_AUTHORIZATION $http_authorization;
+
+ fastcgi_buffers 16 16k;
+ fastcgi_buffer_size 32k;
+ }
+
+ location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
+ expires max;
+ log_not_found off;
+ }
+}