Working NGINX Configuration for Mautic 4 on Plesk

Your software
My Mautic version is: 4.4.2
My PHP version is: 8.0.23
My Database type and version is: MariaDB 10.4.26

I just wanted to share my configuration with anyone looking to run Mautic 4 on Plesk using NGINX for maximum performance. I’m noticing quite the improvement in page load times. Just add this to the Additional NGINX Directives in your Apache & NGINX settings, uncheck “Proxy Mode” and click Apply. I also have PHP set to FPM Application Served by NGINX in the Host Settings.

rewrite ^/(vendor|translations|build)/.* /index.php break;

location / {

	# First attempt to serve request as file, then
	# as directory, then fall back to index.html
	# one option: try_files $uri $uri/ /index.php$is_args$args;
	try_files $uri /index.php$is_args$args;
	# Uncomment to enable naxsi on this location
	# include /etc/nginx/naxsi.rules
}

# Deny everything else in /app folder except Assets folder in bundles
location ~ /app/bundles/.*/Assets/ {
	allow all;
	access_log off;
}
location ~ /app/ { deny all; }

# Deny everything else in /addons or /plugins folder except Assets folder in bundles
location ~ /(addons|plugins)/.*/Assets/ {
	allow all;
	access_log off;
}
# location ~ /(addons|plugins)/ { deny all; }

# Deny all php files in themes folder
location ~* ^/themes/(.*)\.php {
	deny all;
}

# Don't log favicon
location = /favicon.ico {
	log_not_found off;
	access_log off;
}

# Don't log robots
location = /robots.txt  {
	access_log off;
	log_not_found off;
}

# Deny yml, twig, markdown, init file access
location ~* /(.*)\.(?:markdown|md|twig|yaml|yml|ht|htaccess|ini)$ {
	deny all;
	access_log off;
	log_not_found off;
}

# Deny all attempts to access hidden files/folders such as .htaccess, .htpasswd, .DS_Store (Mac), etc...
location ~ /\. {
	deny all;
	access_log off;
	log_not_found off;
}

# Deny all grunt, composer files
location ~* (Gruntfile|package|composer)\.(js|json)$ {
	deny all;
	access_log off;
	log_not_found off;
}

location ~*  \.(jpg|jpeg|png|ico|pdf)$ {
	expires 15d;
}

# Deny access to any files with a .php extension in the uploads directory
location ~* /(?:uploads|files)/.*\.php$ {
	deny all;
}

# Solve email tracking pixel not found
location ~ email/(.*).gif {
	try_files $uri /index.php?$args;
}

# Solve JS Loading 404 Error
location ~ (.*).js {
	try_files $uri /index.php?$args;
}
2 Likes