Answer the question
In order to leave comments, you need to log in
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;
}
}
root /var/www/default/yii2-test-job/web;
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question