0

I have a usecase where a files are grouped and each group can be served for a specific domain name in nginx server. I am not sure how can I acheive that. valid_referer is something which is similar but that works on referer header not on original url. Is there anything similar to valid_referer like valid_origin ?

with valid refererer my config looks like this. But would prefer to handle same via origin condition instead.

location /landing/jack/ {
        valid_referers ~\.codejack\. ~\.jacktest\.;
        if ($invalid_referer) {
            return 403;
        }
    }

Edit: files are grouped via location. So each location can say to be linked to one or more origins.

location /landing/google/ {
        valid_referers ~\.google\.;
        if ($invalid_referer) {
            return 403;
        }
    }

location /landing/stackoverflow/ {
        valid_referers ~\.stackoverflow\.;
        if ($invalid_referer) {
            return 403;
        }
    }

All I need is conditional way where I use origin url instead of referer url.

thecodejack
  • 12,689
  • 10
  • 44
  • 59

1 Answers1

0

I think you are looking for nginx server blocks

Example in your config file you can have like this.

server {
    server_name sub1.yourdomain.com;
    root /var/www/sub1;
    index index.html;
}

server {
    server_name sub2.yourdomain.com;
    root /var/www/sub2;
    index index.html;
}
server {
    server_name sub3.yourdomain.com;
    root /var/www/sub3;
    index index.html;
}

For more information, https://www.nginx.com/resources/wiki/start/topics/examples/server_blocks/

Sam
  • 4,046
  • 8
  • 31
  • 47
  • actually these are additional static folders over ones which are same across domains....is there any other way? – thecodejack Sep 13 '21 at 07:11