[nginx] nginx判断文件存在直接返回,不存在的时候才执行反向代理

当开启了反向代理以后,根目录的文件就不能被访问的到了,这个时候可以使用这个技巧来实现

当文件存在的时候,不走反向代理,直接返回

当文件不存在的时候,正常走反向代理

location /
{
   try_files $uri  @gofly;

}
location @gofly{
    proxy_pass http://127.0.0.1:8083;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    
    add_header X-Cache $upstream_cache_status;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";    

    #Set Nginx Cache
    
        add_header Cache-Control no-cache;
}