Nginx for second Yii application


UrlManger working well in the first application (frontend), but I have trouble for second Yii application for nginx setup. My second application is a directory ‘/admin’. I tried to follow Yii 2 model for frontend and backend nginx setup, but still won’t work.

Server: ubuntu 16.04

Yii 1.17

Nginx 1.10.1

php 7

And here my current nginx setup

server {

    set $host_path "/var/www";

    access_log  /var/www/log/access.log;


    root   $host_path/html;

    set $yii_bootstrap "index.php";

    charset utf-8;

    location / {

        index  index.html $yii_bootstrap;

        try_files $uri $uri/ /$yii_bootstrap?$args;


    #location /admin {

    #        return 301 /admin/;


    #location /admin/ {

    #        alias /var/www/html/;

    #        try_files $uri $uri/ @handler;

    #       location ~ \.php$ {

    #                include fastcgi.conf;

    #        }


    #location @handler {

    #        rewrite / /admin/index.php?$args;


    location ~ ^/(protected|framework|themes/\w+/views) {

        deny  all;


    #avoid processing of calls to unexisting static files by yii

    location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {

        try_files $uri =404;


    # pass the PHP scripts to FastCGI server listening on


    location ~ \.php {

        include snippets/fastcgi-php.conf;

	fastcgi_pass unix:/run/php/php7.0-fpm.sock;

	fastcgi_split_path_info  ^(.+\.php)(.*)$;

	fastcgi_read_timeout 9999;

        #let yii catch the calls to unexising PHP files

        set $fsn /$yii_bootstrap;

        if (-f $document_root$fastcgi_script_name){

            set $fsn $fastcgi_script_name;



        #include fastcgi_params;

        fastcgi_param  SCRIPT_FILENAME  $document_root$fsn;

        #PATH_INFO and PATH_TRANSLATED can be omitted, but RFC 3875 specifies them for CGI

        fastcgi_param  PATH_INFO        $fastcgi_path_info;

        fastcgi_param  PATH_TRANSLATED  $document_root$fsn;


    # prevent nginx from serving dotfiles (.htaccess, .svn, .git, etc.)

    location ~ /\. {

        deny all;

        access_log off;

        log_not_found off;



Thank you

There was some discussions on the same issue two years before. The result was your problem did not get the solution.

Solution was obtained when the backend was used instead of ‘\admin’ it was used as in the same form which we are getting.

So instead of one server variable - you should use 2 server variables

  • root of each server variable will be webdirectory of backend\frontend respectively.

in this case prettyUrls work.

Forgot to add, you may have to use separate domains or subdomains for these two.


Thank you…