Skip to main content

Correct Settings for running Drupal with Plesk and nginx

Submitted by daniel on

I recently realised that I was getting some strange behaviour when running Drupal X on Plesk Obsidian, when set to use PHP is run by and FPM application served with with nginx, such as the index.php showing on links and navigation items. Turns out I needed to add some additional configuration to get this working correctly.

This is a wip but hopefully provides some reference for my self and other who want to configure Drupal correctly when hosting on a Plesk server.

Usually the combination of NGINX as Proxy for Apache works fine for Drupal 8 in Plesk but for those who would like to use NGINX solo you will find this recipe on www.nginx.com: 

Drupal | NGINX 

But this does unfortunately not work without modifications for Plesk managed server. You need some modifications as mentioned below. You can use the following configuration for NGINX in Plesk - which works fine in my case. 

Applying this you must just take care of fastcgi_pass unix:/var/run/plesk/plesk-php74-fpm.sock; This works for me as I use php 7.4 but depends on your configuration concerning php.

#NGINX configuration start
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;
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 ~ \..*/.*\.php$ {
return 403;
}
location ~ ^/sites/.*/private/ {
return 403;
}
location ~ ^/sites/[^/]+/files/.*\.php$ {
deny all;
}
location ~* ^/.well-known/ {
allow all;
}
location ~ (^|/)\. {
return 403;
}
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;
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;
fastcgi_pass unix:/var/run/plesk/plesk-php74-fpm.sock; #(depends on your configuration)
}
location ~ ^/sites/.*/files/styles/ {
try_files $uri @rewrite;
}
location ~ ^(/[a-z\-]+)?/system/files/ {
try_files $uri /index.php?$query_string;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
try_files $uri @rewrite;
expires max;
log_not_found off;
}
if ($request_uri ~* "^(.*/)index\.php(.*)") {
return 307 $1$2;
}
#NGINX configuration end

 

https://talk.plesk.com/threads/nginx-configuration-for-drupal-8-x-without-apache-for-plesk-obsidian-ubuntu-18-x.355322/

Add new comment

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.