Nginx最佳实践,用于避免在提供静态与代理数据时

时间:2018-06-08 17:04:30

标签: nginx nginx-reverse-proxy

nginx的"common pitfalls"描述表明这很糟糕:

server {
    root /var/www/example.com;
    location / {
        if (!-f $request_filename) {
            break;
        }
    }
}

......应该用这个代替:

server {
    root /var/www/example.com;
    location / {
        try_files $uri $uri/ /index.html;
    }
}

但是我怎么能在这种情况下消除if:

if (-f $request_filename) {
    break;
}

if (!-f $request_filename) {
    proxy_pass http://localhost:8080;
    break;
}

0 个答案:

没有答案