Created
February 22, 2017 22:12
-
-
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)
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
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" |
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
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 |
...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
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 containingnetwork_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 usingdocker log
(ordocker-compose log
) on the rsyslog service.