Last active
October 18, 2024 06:39
-
-
Save Gazer/5879350 to your computer and use it in GitHub Desktop.
Nginx example to redirect users to a "Comming soon portal" if they are not developers.
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 { | |
listen 80; | |
server_name localhost; | |
location @until { | |
# Static "comming soon" directory with index.html and assets | |
root /var/www/; | |
index index.html; | |
} | |
location /let-me-in { | |
# Set a cookie to allow this user see the real site! | |
add_header Set-Cookie dev_access=1; | |
return 301 http://localhost/; | |
} | |
location / { | |
# If HTTP Error 418 is raised, we "render" @until location | |
# 418 is the code for "internal redirection" used by nginx | |
error_page 418 = @until; | |
recursive_error_pages on; | |
# Tricky part. Check cookie and deny access if not set | |
set $developer N; | |
if ($http_cookie ~* "dev_access") { | |
set $developer S; | |
} | |
# No cookie, so no access. Redirect to "@until" | |
if ($developer = N) { | |
return 418; | |
} | |
# Normal site, let the user see it | |
root /path/to/rails/app/public; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $http_host; | |
proxy_redirect off; | |
proxy_pass http://127.0.0.1:3000/; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment