Skip to content

Instantly share code, notes, and snippets.

@codification
Created February 22, 2017 22:12
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codification/1733666f9ce9072b14906c4966c2abb5 to your computer and use it in GitHub Desktop.
Save codification/1733666f9ce9072b14906c4966c2abb5 to your computer and use it in GitHub Desktop.
Docker haproxy with http logging through syslog proxying to local port (for debugging)
version: "2"
services:
rsyslog:
image: jumanjiman/rsyslog
proxy:
image: haproxy
volumes:
- ./:/cfg
volumes_from:
- rsyslog
command: haproxy -f /cfg/haproxy.cfg
network_mode: "host"
ports:
- "80:80"
global
daemon
maxconn 256
log /var/run/rsyslog/dev/log local0
log /var/run/rsyslog/dev/log local1
defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend http-in
bind *:80
default_backend servers
capture cookie COOKIENAME len 32
log global
option httplog
backend servers
server server1 127.0.0.1:8080 maxconn 32
@codification
Copy link
Author

Fire up using docker-compose (using -f docker-compose-haproxy-with-logging.yml unless you change the name of the first file). This expects your application (that you want to proxy to, like I did, for debugging) to be residing on port 8080 on your local machine. If it is already in a container that is fine too - just remove the line containing network_mode: host since it is not needed (and should be avoided) and change the hostname for the backend in haproxy.cfg accordingly. The proxy will start up and occupy port 80 locally and logs can be seen by simply using docker log (or docker-compose log) on the rsyslog service.

@codification
Copy link
Author

...and the reason for learning this was that I was debugging cookies and http requests. This middleman at least could tell me who was lying. That is the reason the capture cookie ... line is there. Can be removed or changed to cookie whose name matches yours (the "COOKIENAME" part).

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