nginx try_files功能使用


nginx try_files如果想多次判断的话下面的方式是不行的,比如:

try_files $uri @eva2480 @eva24;

这样写永远都是最后一个参数生效,可以使用下面的方式,下级判断。

server  {
listen  81;
server_name  xxx1;
access_log  /usr/local/nginx/logs/access81.log  access;
root  /b;
error_page  405     =200 $uri;
location / {
try_files $uri @eva2480;
}
location @eva2480 {
proxy_redirect off ;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://xxx2;

}

}

server  {
listen  80;
server_name  xxx;
access_log  /usr/local/nginx/logs/access.log  access;
error_page  405     =200 $uri;
location / {
root  /2b;
try_files $uri @evaone;
}
location @evaone {
proxy_redirect off ;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://xxx1:81;
}


Whatever is worth doing is worth doing well.