N
N
nepster-web2015-08-19 21:10:47
Nginx
nepster-web, 2015-08-19 21:10:47

Nginx, why doesn't root/alias work in location?

I have the following nginx configuration:

server{
    #имя сервера:
    server_name "my_ip";

    charset utf-8;
    client_max_body_size 128M;

    # корневая директория
    index index.php index.html;

    root /var/www/default;

    location /
    {
        root /var/www/default;
    }

    location /yii2-test-job
    {
        alias /var/www/default/yii2-test-job/web;
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        try_files $uri = 404;
        include fastcgi_params;
        fastcgi_pass  unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;

        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    }

}

The problem is, at the address my_ip/yii2-test-job 404 error climbs. The directory /var/www/default/yii2-test-job/web - 100% exists. Just my_ip works.
If you put it outside the location
root /var/www/default/yii2-test-job/web;
Everything will work. But why does location /yii2-test-job not work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2015-08-20
@Lynn

Of course it works, but only in the context of location /yii2-test-job.
As soon as try_files made an internal redirect to /index.php(by the way, I never understood what for to add there ?$args), you get into location ~ \.php$and the root of the server acts there.
UPD: I would write like this:

server {
    root /var/www/default;
    index index.php index.html;

    location /yii2-test-job {
        alias /var/www/default/yii2-test-job/web;
        try_files $uri $uri/ /yii2-test-job/index.php;

        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass  unix:/var/run/php5-fpm.sock;
            include fastcgi_params;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        }
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question