fbpx
ISTOTEXNIKI
WEB SOLUTIONS
Nginx rewrite rules σε Plesk

Nginx rewrite rules in Plesk

Nginx rewrite rules in Plesk if you use exclusively Nginx with PHP-FPM instead of the default setting Apache

This is required for PHP platforms like OpenCart and WordPress, where for your links to work properly, you will need to make a change to the “Additional nginx directives” field within the Plesk.

When the setup is based on Apache, permalinks are set via a .htaccess file. However, in nginx only option it doesn't read this file, so it has to be added directly to the Plesk configuration so that the server can read all url's correctly and not lead to 404 errors.

The process:

  • 1. Open the desired domain in Plesk
  • 2. Click on the “Hosting & DNS” tab
  • 3. Select “Apache & nginx settings”
  • 4. There, after deactivating the “Proxy mode” option so that only the nginx web server works, at the end in the “Additional nginx directives” field, fill in:

For OpenCart

rewrite ^/sitemap.xml$ /index.php?route=extension/feed/google_sitemap last; rewrite ^/googlebase.xml$ /index.php?route=extension/feed/google_base last; rewrite ^/system/storage/(.*) /index.php?route=error/not_found last; if (!-f $request_filename){ set 1TP4Rule_3 11TP4Rule_3; } if (!-d $request_filename){ set $rule_3 2$rule_3; } if ($uri !~ ".*\.(ico|gif|jpg|jpeg|png|js|css)"){ set $rule_3 3$rule_3; } if ($rule_3 = "321"){ rewrite ^/([^?]*) /index.php?_route_=$1 last; }

For WordPress

if (!-e $request_filename) { rewrite ^(.+)$ /index.php?q=$1 last; }

Caution: Note that in a nginx only setting (Proxy option disabled that is) that there is filled in the .htaccess file located in the folder (/httpsdocs) has no effect. In order for your commands to work there, you must activate the “Proxy” option again, where in this case the combination of Apache and Nginx will work.

This article applies to Plesk Onyx and Plesk Obsidian.

ΚΛΕΙΣΙΜΟ