-
-
Save bool-dev/031cfd05e3defa19466e50df6be8207a to your computer and use it in GitHub Desktop.
Nginx config to test regex.
This file contains hidden or 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
# 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; | |
} | |
} | |
} |
This file contains hidden or 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
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment