Skip to content

Instantly share code, notes, and snippets.

@jmervine
Last active March 19, 2020 06:17
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save jmervine/8943627 to your computer and use it in GitHub Desktop.
Save jmervine/8943627 to your computer and use it in GitHub Desktop.
Nginx config to test regex.
# Usage:
#
# Start with:
#
# sudo /use/local/sbin/nginx -c /path/to/this/nginx.conf
#
# Tail logs:
#
# $ sudo tail -f /tmp/access.log /tmp/error.log /tmp/match.log
#
# Generate load:
#
# $ cat ./urls.txt | xargs curl -i
#
# See below for urls.txt example.
#
# Matches should be in /tmp/match.log with a 200 status.
#
# Everything else should be in /tmp/access.log with a 404 status.
worker_processes 1;
http {
include /usr/local/etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$status $request'; # e.g. "200 GET /foo HTTP/1.1"
access_log /tmp/access.log main;
error_log /tmp/error.log;
server {
listen 8888;
server_name localhost;
location ~ ^/good[0-9]$ { # << regex here
access_log /tmp/match.log main;
return 200;
}
location / {
return 404;
}
}
}
http://localhost:8888/good1
http://localhost:8888/good2
http://localhost:8888/good3
http://localhost:8888/bad1
http://localhost:8888/bad2
http://localhost:8888/bad3
http://localhost:8888/good4
http://localhost:8888/bad4
http://localhost:8888/good5
http://localhost:8888/bad5
@xeoncross
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment