Created
December 30, 2014 13:01
-
-
Save nikolaymatrosov/f8bda2f66f848b3eec7d to your computer and use it in GitHub Desktop.
Lua redirects based on backend response
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 7777; | |
location / { | |
root /tmp/www; | |
index index.html; | |
try_files $uri @lua; | |
} | |
location /api { | |
rewrite /api/(.*)$ $1 break; | |
proxy_pass http://localhost:7778; | |
} | |
location @lua { | |
default_type 'text/plain'; | |
content_by_lua ' | |
local res = ngx.location.capture("/api/"..ngx.var.uri) | |
if res.status == 200 then | |
ngx.redirect("http://google.com") | |
end | |
if res.status == 404 then | |
ngx.redirect("http://yandex.ru") | |
end | |
'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment