Hi,
today i want to explain how to configure a app with framework Yii 2 on your hosting Plesk.
In my case i have Plesk 17.8, the problem is how to configure the subdirectory and so how to convert the htaccess of Yii 2 app.

On Plesk 17 you must to configure the site, on run PHP-FPM un on nginx.
So go in the Hosting Setting of the domain:

Hosting Setting

So go in the Hosting Setting of the domain:

Apache & nginx Settings

You must to disable Proxy mode

Than we must to configure the Additional nginx directives
So go in the Apache & nginx Settings of the domain
Than into Additional nginx directives copy this code (change YOURDOMAIN with the domain that you want to configure):

set $base_root /var/www/vhosts/YOURDOMAIN/httpdocs;

charset UTF-8;
index index.php index.html;

location / {
	root $base_root/frontend/web;
	try_files $uri $uri/ /frontend/web/index.php$is_args$args;

	location ~ ^/assets/.+\.php(/|$) {
		deny all;
	}
}

location /admin {
	alias $base_root/backend/web/;

	# prevent the directory redirect to the URL with a trailing slash
	location = /admin {
		# if your location is "/backend", try use "/backend/backend/web/index.php$is_args$args"
		# bug ticket: https://trac.nginx.org/nginx/ticket/97
		try_files $uri /backend/web/index.php$is_args$args;
	}

	try_files $uri $uri/ /backend/web/index.php$is_args$args;

	location ~ ^/admin/assets/.+\.php(/|$) {
		deny all;
	}
}

location ~ ^/.+\.php(/|$) {
	rewrite (?!^/((frontend|backend)/web|admin))^ /frontend/web$uri break;
	rewrite (?!^/backend/web)^/admin(/.+)$ /backend/web$1 break;

	fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
	fastcgi_param PATH_INFO $fastcgi_path_info;
	fastcgi_pass "unix:///var/www/vhosts/system/YOURDOMAIN/php-fpm.sock";
	include /etc/nginx/fastcgi.conf;
}

location ~ /\. {
	deny all;
}

If you want you can enable nginx caching

Press “OK” and enjoy

3 Comments

  1. Hi,

    Thank you for this. Plesk 18 gives an error when updating nginx additional directives:

    Invalid nginx configuration: nginx: [emerg] duplicate location “/” in /var/www/vhosts/system/YOURDOMAIN/conf/vhost_nginx.conf:6 nginx: configuration file /etc/nginx/nginx.conf test failed

    Did you tried this?

    Thanks again

  2. Try to change

    location / {
    root $base_root/frontend/web;
    with

    location ~ / {
    root $base_root/frontend/web;

  3. As mentioned in https://support.plesk.com/hc/en-us/articles/213912945, please use the following approach additional to the comment from Cicciokr
    —————-
    if (!-e $request_filename) {
    set $test P;
    }
    if ($uri !~ ^/(plesk-stat|webstat|webstat-ssl|ftpstat|anon_ftpstat|awstats-icon|internal-nginx-static-location|status_phpfpm)) {
    set $test “${test}C”;
    }
    if ($test = PC) {
    rewrite ^/(.*)$ /index.php?$1;
    }
    ——————-

Leave a Reply

Your email address will not be published. Required fields are marked *