server { listen 80; listen [::]:80; server_name example.com www.example.com; root /var/www/html/drupal; access_log /var/log/nginx/example.com/access.log; error_log /var/log/nginx/example.com/error.log; 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 ~ ^/sites/.*/private/ { return 403; } # Block access to scripts in site files directory # location ~ ^/sites/[^/]+/files/.*\.php$ { deny all; } location ~ (^|/)\. { return 403; } location / { try_files $uri /index.php?$query_string; } location @rewrite { rewrite ^/(.*)$ /index.php?q=$1; } location ~ /vendor/.*\.php$ { deny all; return 404; } location ~ '\.php$|^/update.php' { fastcgi_split_path_info ^(.+?\.php)(|/.*)$; 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; # Pass the appropriate php-fpm sock version here fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; } location ~ ^/sites/.*/files/styles/ { try_files $uri @rewrite; } # Handle private files through Drupal. Private file's path can come # with a language prefix. # location ~ ^(/[a-z\-]+)?/system/files/ { try_files $uri /index.php?$query_string; } location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|tiff|woff)$ { try_files $uri @rewrite; expires max; log_not_found off; } # Very rarely should these ever be accessed outside of your lan # location ~* \.(txt|log|bak|sql)$ { # Uncomment if you want to allow for some IP addresses or LAN # Make sure to add correct IP addresses or range. # allow 192.168.0.0/16; deny all; } }