Nginx config for Yii2 advanced project

Author: Rafal Marguzewicz
Categories: Yii2

nginxTo work properly Yii2 framework with NGINX, have to do:
Do poprawnej pracy frameworka Yii z serwerem HTTP Nginx, należy:

  1. Install framework Yii2 template advanced
  2. Configuration NIGNX in config file
  3. Configuration Yii2 in backend config file

Configuration NIGNX

Envirement list:
path to frontend folder: /home/user/www/folder-app/frontend/
path to backend folder /home/user/www/folder-app/backend/
Url frontend:
Url backend:


server {
	root         /home/user/www/folder-app;
	access_log   off;
	charset      utf-8;

	location / {
	        root  /home/user/www/folder-app/frontend/web;
		    try_files  $uri /index.php?$args;


    location ~* \.php$ {
        try_files  $uri /frontend/web$uri =404;
        include  fastcgi.conf;

    location ~* \.(css|js|jpg|jpeg|png|gif|bmp|ico|mov|swf|pdf|zip|rar)$ {
        access_log  off;
        log_not_found  off;
        try_files  $uri /frontend/web$uri =404;

    location /admin {
        alias /home/user/www/folder-app/backend/web;
        try_files  $uri /backend/web/index.php?$args;

        location = /admin/ {
           return  301 /admin;

        location ~* ^/admin/(.+\.php)$ {
            try_files  $uri /backend/web/$1?$args;

        # avoid processing of calls to non-existing static files by Yii (uncomment if necessary)
        location ~* ^/admin/(.+\.(css|js|jpg|jpeg|png|gif|bmp|ico|mov|swf|pdf|zip|rar))$ {
            try_files $uri /backend/web/$1?$args;

Config Yii2 backend file

return [
	'homeUrl' => '/admin/',
    'components' => [

		'request' => [
            'baseUrl' => '/admin',

If this localhost, don’t forget add to hosts

sudo nano /etc/hosts

Example /etc/hosts on localhost       localhost       m

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

Name *
Email *

Read previous post:
Yii2 form field

This description is for Yii2 forms with model. Form can have many type of fields. e.g: Field input (single-line) Field...