Skip to content

Instantly share code, notes, and snippets.

@cnst
Last active July 25, 2017 03:09
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 cnst/3521404dfdf5cb7b4c526b5c6dff38ff to your computer and use it in GitHub Desktop.
Save cnst/3521404dfdf5cb7b4c526b5c6dff38ff to your computer and use it in GitHub Desktop.
# Author: Constantine A. Murenin (cnst) http://cnst.su/
#
# Automatically redirect `/search/?search=nginx` to `/search/nginx.html` externally,
# such that the location in the browser will change, but then process the request
# with the backend as if no such redirect has ever happened.
server {
listen [::]:7380;
location = /search/ {
if ($arg_search) {
return 302 /search/$arg_search.html;
}
default_type text/html;
return 200
"<!DOCTYPE html><title>search</title>
<form><input name='search'/></form>\n";
}
location /search/ {
rewrite ^/search/([^/]*)\.html$ /search/?search=$1 break;
proxy_pass http://localhost:7381;
}
location / {
return 403;
}
location = /45257380.nginx.conf {
default_type text/plain;
root /etc/nginx/conf.d;
}
}
server {
listen [::]:7381;
default_type text/plain;
return 200
"$uri\n\t$is_args$args\n$request_uri\n";
}
%
%
%curl -v "localhost:7380/search/?search=test" | & fgrep -e Location -e title
< Location: http://localhost:7380/search/test.html
<head><title>302 Found</title></head>
%
%
%curl "localhost:7380/search/test.html"
/search/
?search=test
/search/?search=test
%
%
%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment