Skip to content

Instantly share code, notes, and snippets.

@TBeijen
Created November 16, 2021 05:55
Show Gist options
  • Save TBeijen/ea9242893fa8591b3d17bb64459f9c16 to your computer and use it in GitHub Desktop.
Save TBeijen/ea9242893fa8591b3d17bb64459f9c16 to your computer and use it in GitHub Desktop.
Nginx: Dump incoming request header (CDN debugging)
# Taken and adapted from https://gist.github.com/phrawzty/62540f146ee5e74ea1ab
#!/usr/bin/env python2
import SimpleHTTPServer
import SocketServer
import logging
import sys
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
PORT = 6677
class GetHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
logging.info(self.headers)
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
Handler = GetHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
logging.info("Server running at port {}".format(PORT))
httpd.serve_forever()
# Taken from https://stackoverflow.com/questions/24380123/how-to-log-all-headers-in-nginx
server {
# (existing config)
location @uwsgi {
include uwsgi_params;
# mirror requests to /mirror
mirror /mirror;
mirror_request_body off;
uwsgi_pass unix:///location/to/uwsgi.sock;
uwsgi_read_timeout 120s;
}
location /mirror {
# Use internal so that location is not available for direct requests
internal;
# Use small timeout not to wait for replies (this is not necessary)
proxy_read_timeout 1;
# Pass headers to logging server
proxy_pass http://127.0.0.1:6677;
# send original request uri in special header
proxy_set_header X-Original-URI $request_uri;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment