N
N
nepster-web2014-05-28 17:37:49
Nginx
nepster-web, 2014-05-28 17:37:49

Yii2 how to reach bakend using nginx?

I am using the following nginx config:

server {
    set $yii_bootstrap "index.php";
    charset utf-8;
    client_max_body_size 128M;

    listen 80; ## listen for ipv4
    #listen [::]:80 default_server ipv6only=on; ## listen for ipv6

    server_name test.site.ru;
    root        /var/www/site.ru/test/frontend/web;
    index       $yii_bootstrap;

    access_log  /var/www/site.ru/logs/test.site.access.log  main;
    error_log   /var/www/site.ru/logs/test.site.error.log;

    location /admin {
        try_files $uri $uri/ /$yii_bootstrap?$args;
        root /var/www/site.ru/test/backend/web;
   }

    location / {
        try_files $uri $uri/ /$yii_bootstrap?$args;
    }

    # uncomment to avoid processing of calls to unexisting ystatic files by yii
    #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
    #    try_files $uri =404;
    #}
    #error_page 404 /404.html;

    location ~ \.php$ {
        include fastcgi.conf;
        fastcgi_pass   127.0.0.1:9000;
        #fastcgi_pass unix:/var/run/php5-fpm.sock;
    }

    location ~ /\.(ht|svn|git) {
        deny all;
    }
}

But it doesn't work out to make access to the backend through the request site.ru/admin
Please tell me how to solve this matter?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Z
Zohei, 2014-10-30
@Zohei

Hit the same wall! Did you end up solving the problem? =)
.....An hour later.... The problem was solved insanely simple and not through nginx... it was enough to disable caching of web pages in firebug and not puzzle over configs...
Here is the minimum working configuration:

server {
    listen       80;
    server_name  example.ru;
    root         /home/example/data/www/example.ru;
    index        index.html index.php;
    charset      utf-8;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location /admin {
         try_files $uri $uri/ /admin.php?$args;
    }

    location ~ \.php$ {
        root   /home/example/data/www/example.ru;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /home/example/data/www/example.ru$fastcgi_script_name;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include        fastcgi_params;
        fastcgi_param  PATH_INFO $fastcgi_path_info;
    }
}

It remains to add redirects from www and slashes at the end and rejoice.

A
Alexander Gubarev, 2014-06-02
@AlexGx

I join the question, I tried in a similar way - it did not work.

Y
Yuri Efin, 2016-03-01
@Gambits

try specifying listen site.loc:80 in the config; ## listen for ipv4 - for frontend and backend.site.loc:80; - for the backend - respectively, your domain names should be - do not copy stupidly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question