2

I want to setup a reverse proxy for serving images stored in S3.
I dont want to allow access to images if referrer is not example.com
But I want to allow multiple crawlers for example google bot, bing bot etc (based on user_agent) to access the images.
I also want to allow my android app to access the images (based on custom header say X-Application: ExampleApp)

How do I configure nginx to do so ?

Rahul Prasad
  • 8,074
  • 8
  • 43
  • 49

1 Answers1

1

That comes to using 3 IF's which is not going to work due to IF limitations. What you can do is 2 things, set up MAP to deal with the 3 tests (setting true or false values) then inside the server block use Lua to combine the 3 test values into one and use a single IF (or pure Lua) in the location block to allow/deny access.

map $referrer $usestring1 {
 default     0;
 ~^google$   1;
}
map $user_agent $usestring2 {
 default     0;
 ~^google$   1;
}
etc....

location / {
    content_by_lua '
      local s = ngx.var.usestring1;
      local t = ngx.var.usestring2;
      if s+t == 2 then return ngx.exit(503); end;
    ';
  etc...........
itpp13
  • 444
  • 2
  • 6