Skip to content

Instantly share code, notes, and snippets.

@notsobad
Created March 24, 2014 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notsobad/9742534 to your computer and use it in GitHub Desktop.
Save notsobad/9742534 to your computer and use it in GitHub Desktop.
Redirect all request to a server except static files.
server {
listen 80 ;
server_name 127.0.0.1;
client_header_timeout 60s;
client_body_timeout 30s;
send_timeout 60s;
#access_log /var/log/redirect.access_log redirect;
location / {
access_by_lua '
local uri = ngx.var.uri
local method = ngx.req.get_method()
if not ngx.re.match(method,"^GET|POST$","oj") then
return ngx.exit(ngx.HTTP_NOT_ALLOWED)
end
if ngx.re.match(uri, "\.(jp?g|png|gif|bmp|ico|rar|zip|gz|flv|swf|js|css)$", "ioj") then
return ngx.exit(ngx.HTTP_NOT_FOUND)
end
return ngx.redirect("http://www.notsobad.me/?a=1", ngx.HTTP_MOVED_TEMPORARILY)
';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment