ajay sharma
ajay sharma

Reputation: 11

Load a site based on header request in NGINX

I have different static sites hosted at http://static.example.com/ and I want to load different versions of the site based on the X-Site-version header sent to Nginx server. If no header is present than a default version should be loaded.

PSEUDO CODE

if header X-Site-version === 2
 load /www/static/v2

if header X-Siter-version === 1
 load /www/static/v1

else
 load /www/static/v0

Upvotes: 1

Views: 540

Answers (1)

lifeisfoo
lifeisfoo

Reputation: 16294

You can try with the root directive to set the content resolution directory and with the map directive to set a default directory when your header is missing. A configuration like this should work:

map $http_x_site_version $site_directory {
    default    $http_x_site_version;
    ''         v0;
}

server {
        location / {
            root /www/static/$site_directory;
        }
}

Upvotes: 1

Related Questions