#Google Pagespped settings
pagespeed on;
pagespeed FileCachePath "/var/cache/nginx/";
pagespeed RewriteLevel OptimizeForBandwidth;
pagespeed RewriteLevel CoreFilters;
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
#Cache Control Immutable
location ~* .(js|jpg|jpeg|gif|png|css|tgz|gz|rar|bz2|doc|pdf|ppt|tar|wav|bmp|rtf|swf|ico|flv|txt|woff|woff2|svg)$ {
etag on;
if_modified_since exact;
add_header Pragma "public";
add_header Cache-Control "max-age=31536000, public";
}
# serve either Gzip or Brotli depending on the user's browser
location ~ ^/sites/.*/files/(css|js) { brotli_static on; gzip_static on; }
#gzip Settings
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_static on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types application/javascript application/rss+xml application/vnd.ms-fontobject application/x-font application/x-font-opentype application/x-font-otf application/x-font-truetype application/x-font-ttf application/x-javascript application/xhtml+xml application/xml font/opentype font/otf font/ttf image/svg+xml image/x-icon text/css text/javascript text/plain text/xml;
# Brotli Settings
brotli on;
brotli_static on;
brotli_buffers 16 8k;
brotli_comp_level 6;
brotli_types *;
#location ~ / {
# index index.php index.cgi index.pl index.html index.xhtml index.htm index.shtml;
# try_files $uri $uri /index.php$is_args$args;
#}
location ~ / {
# try_files $uri @rewrite; # For Drupal <= 6
try_files $uri /index.php?$query_string; # For Drupal >= 7
}
location @rewrite {
rewrite ^/(.*)$ /index.php?q=$1;
}
#Drupal stuff
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ \..*/.*\.php$ {
return 403;
}
location ~ (^|/)\. {
return 403;
}
location ~ ^/sites/.*/private/ {
return 403;
}
# Don't allow direct access to PHP files in the vendor directory.
location ~ /vendor/.*\.php$ {
deny all;
return 404;
}
# Block access to scripts in site files directory
location ~ ^/sites/[^/]+/files/.*\.php$ {
deny all;
}
# Allow "Well-Known URIs" as per RFC 5785
location ~* ^/.well-known/ {
allow all;
}
# Fighting with Styles? This little gem is amazing.
# location ~ ^/sites/.*/files/imagecache/ { # For Drupal <= 6
location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7
try_files $uri @rewrite;
}
# Handle private files through Drupal. Private file's path can come
# with a language prefix.
location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7
try_files $uri /index.php?$query_string;
}
# In Drupal 8, we must also match new paths where the '.php' appears in the middle, such as update.php/selection. The rule we use is strict, and only allows this pattern with the update.php front controller.
# This allows legacy path aliases in the form of log/index.php/legacy-path to continue to route to Drupal nodes. If you do not have any paths like that, then you might prefer to use a laxer rule, such as: location ~ \.php(/|$) {
# The laxer rule will continue to work if Drupal uses this new URL pattern with front controllers other than update.php in a future release.
location ~ '\.php$|^/update.php' {
# Ensure the php file exists. Mitigates CVE-2019-11043
#try_files $uri =404;
try_files $uri $uri/ /index.php?q=$uri&$args;
#fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# Security note: If you're running a version of PHP older than the latest 5.3, you should have "cgi.fix_pathinfo = 0;" in php.ini.
# See http://serverfault.com/q/627903/94922 for details.
include fastcgi_params;
# Block httpoxy attacks. See https://httpoxy.org/.
fastcgi_param HTTP_PROXY "";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param QUERY_STRING $query_string;
fastcgi_intercept_errors on;
# PHP 7 socket location.
fastcgi_pass unix:/var/www/vhosts/system/YOURDOMAIN/php-fpm.sock;
}
# Enforce clean URLs
# Could be done with 301 for permanent or other redirect codes.
if ($request_uri ~* "^(.*/)index\.php(.*)") {
return 307 $1$2;
}