如果存在则使用nginx返回文件,传递给代理else

任务是从查询参数获取参数的文件名,检查文件是否存在,以及:

  • 如果存在,则返回此文件
  • 否则,将请求传递给Django后端

我设法得到参数,并检查文件是否存在,但我不知道下一步该怎么做:

location /media/ { set $file "/static/$arg_key"; if (-f $file) { // Return the file } else { // include proxy_params; // proxy_pass http://unix:/opt/django/gunicorn.sock; } } 

这是try_files的用途。

例如:

 location /media/ { try_files /static/$arg_key @django; } location @django { proxy_whatever...; }