Skip to content

Instantly share code, notes, and snippets.

@etiennepouliot
Last active June 20, 2018 22:48
Show Gist options
  • Save etiennepouliot/c2fff3de297ee2a9fec10c4ed34f80ec to your computer and use it in GitHub Desktop.
Save etiennepouliot/c2fff3de297ee2a9fec10c4ed34f80ec to your computer and use it in GitHub Desktop.
Haproxy configuration to share a port 80/443 with nginx (or Apache, etc) and SSH
ssh foo.example.com -p 80
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
# turn on stats unix socket
stats socket /var/lib/haproxy/stats
defaults
timeout connect 5000
timeout client 50000
timeout server 50000
frontend main
mode tcp
bind 0.0.0.0:80
tcp-request inspect-delay 5s
#find ssh signature
use_backend ssh if { payload(0,7) -m bin 5353482d322e30 }
default_backend webserver
backend ssh
mode tcp
timeout server 2h
timeout client 2h
server ssh-localhost 127.0.0.1:22
backend webserver
mode tcp
server webserver-localhost 127.0.0.1:8080
server {
listen 127.0.0.1:8080;
....
}
@etiennepouliot
Copy link
Author

Should also work with TLS/SSL, juste need to use tcp backend to a nginx/apache serving the certificate.

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