Last active
February 21, 2017 11:52
-
-
Save alekseyl/c6c4d053e714eae5b93b460c3268661f to your computer and use it in GitHub Desktop.
Conditional location selection with try_files. It may be useful in cases of A\B version of a site running on same domain name. You can do sticky cookie with this example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
set $versioned_location @version_one; | |
if ( $cookie_condition ) { | |
set $versioned_location @version_two; | |
} | |
if ( $cookie_site_version = "version_one" ) { | |
set $versioned_location @version_one; | |
} | |
location / { | |
try_files $uri $versioned_location; | |
} | |
# sticky cookie example | |
location @version_one { | |
add_header Set-Cookie site_version=version_one; | |
} | |
location @version_two { | |
} | |
# also if you have other locations configs, you need to rewrite them too | |
# for example for /assets location you may rewrite it to: | |
location /assets { | |
try_files $uri $branched_location; # <----difference | |
expires 1y; | |
gzip_static on; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment