Nginx config for Yii2 advanced project

Author: Rafal Marguzewicz
Published:
Categories: Yii2
Tags:


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: http://yii.dev
Url backend: http://yii.dev/admin

 

server {
	server_name yii.dev;
	
	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 yii.dev to hosts

sudo nano /etc/hosts

Example /etc/hosts on localhost


127.0.0.1       localhost yii.dev pceuropa.dev wordpress.dev
127.0.1.1       m
Nginx config for Yii2 advanced project
4 / 2 votes


Popular search terms:
| |

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...

Close