Advertisement
Guest User

nginx regex map test

a guest
Jul 19th, 2021
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. NGINX config:
  2. =============
  3.  
  4. map $request_uri $new_uri {
  5. "~^/r(/[\S]+)\.(png|jpe?g)\?a=(\d+)$" $1.$2?x=$3;
  6. }
  7.  
  8. server {
  9. listen 80;
  10. server_name localhost;
  11. root html;
  12.  
  13. location / {
  14. index index.html index.htm;
  15. if ($new_uri) {
  16. rewrite ^ $new_uri permanent;
  17. }
  18. }
  19. }
  20.  
  21. cURL log:
  22. =========
  23.  
  24. G:\OpenResty\OpenResty11782\x86>curl -v "http://localhost/r/some/path/image.jpg?a=100"
  25. * Trying 127.0.0.1...
  26. * TCP_NODELAY set
  27. * Connected to localhost (127.0.0.1) port 80 (#0)
  28. > GET /r/some/path/image.jpg?a=100 HTTP/1.1
  29. > Host: localhost
  30. > User-Agent: curl/7.62.0
  31. > Accept: */*
  32. >
  33. < HTTP/1.1 301 Moved Permanently
  34. < Server: openresty/1.17.8.2
  35. < Date: Tue, 20 Jul 2021 03:38:01 GMT
  36. < Content-Type: text/html
  37. < Content-Length: 175
  38. < Location: http://localhost/some/path/image.jpg?x=100?a=100
  39. < Connection: keep-alive
  40. <
  41. <html>
  42. <head><title>301 Moved Permanently</title></head>
  43. <body>
  44. <center><h1>301 Moved Permanently</h1></center>
  45. <hr><center>openresty/1.17.8.2</center>
  46. </body>
  47. </html>
  48. * Connection #0 to host localhost left intact
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement