As part of this tutorial, we will configure a reverse proxy for our sites to work in transparent mode in 10 minutes. Go.
I set the task that transparent routing between the visitor and the final site would work without problems on my server under the leadership of Proxmox with a pool of sites. Because the internet is full of manuals on the basic configuration of Haproxy, I ran into the problem that 99% of these articles describe the work of a proxy server in termination mode, and then the information goes according to an unprotected version (from a proxy to the final VM). This did not suit me and I began to search bit by bit for information on the net. Unfortunately, in our Russian-speaking segment there is little of it (read no) we had to wool the bourgeois segment. I bring the end result to your attention, I think it will definitely work for anyone.
global log /dev/log local0 log /dev/log local1 notice stats socket /haproxy-admin.sock mode 660 level admin stats timeout 30s daemon defaults maxconn 2000 mode http log global option dontlognull # bind *:443 ssl crt . option http-server-close timeout http-request 10s timeout connect 5000 timeout client 50000 timeout server 50000 frontend stats bind *:5000 stats enable stats uri /stats stats refresh 10s stats auth admin:mysupersecretpassword #
Block responsible for ssl to ssl
frontend env_ssl_frontend bind *:443 mode tcp option tcplog tcp-request inspect-delay 10s tcp-request content accept if { req_ssl_hello_type 1 } use_backend bk_app1 if { req.ssl_sni -m end site1.ru } use_backend bk_app2 if { req.ssl_sni -m end counter.site1.ru } use_backend bk_app3 if { req.ssl_sni -m end site2.com } use_backend bk_app4 if { req.ssl_sni -m end site3.msk.ru } use_backend bk_app5 if { req.ssl_sni -m end site4.ru } use_backend bk_app6 if { req.ssl_sni -m end site5.msk.ru } backend bk_app1 mode tcp balance leastconn option tcp-check server main 192.168.1.26:443 send-proxy check backend bk_app2 mode tcp balance leastconn option tcp-check server main 192.168.1.38:443 send-proxy check backend bk_app3 mode tcp balance leastconn option tcp-check server main 192.168.1.37:443 send-proxy check backend bk_app4 mode tcp balance leastconn option tcp-check server main 192.168.1.100:443 check backend bk_app5 mode tcp balance leastconn option tcp-check server main 192.168.1.31:443 send-proxy check backend bk_app6 balance leastconn mode tcp option tcp-check server main 192.168.1.200:443 check
Block responsible for the operation of sites on port 80
frontend public bind *:80 # acl host_subdomain1 hdr(host) -i site1.ru acl host_subdomain2 hdr(host) -i counter.site1.ru acl host_subdomain3 hdr(host) -i site2.com acl host_subdomain4 hdr(host) -i site3.msk.ru acl host_subdomain5 hdr(host) -i site4.ru acl host_subdomain6 hdr(host) -i site5.msk.ru ## acl use_backend subdomain1 if host_subdomain1 use_backend subdomain2 if host_subdomain2 use_backend subdomain3 if host_subdomain3 use_backend subdomain4 if host_subdomain4 use_backend subdomain5 if host_subdomain5 use_backend subdomain6 if host_subdomain6 backend subdomain1 option httpclose option forwardfor cookie JSESSIONID prefix server subdomain-1 192.168.1.26:80 check backend subdomain2 option httpclose option forwardfor cookie JSESSIONID prefix server subdomain-2 192.168.1.37:80 check backend subdomain3 option httpclose option forwardfor cookie JSESSIONID prefix server subdomain-3 192.168.1.31:80 check backend subdomain4 option httpclose option forwardfor cookie JSESSIONID prefix server subdomain-4 192.168.1.100:80 check backend subdomain5 option httpclose option forwardfor cookie JSESSIONID prefix server subdomain-5 192.168.1.200:80 check backend subdomain6 option httpclose option forwardfor cookie JSESSIONID prefix server subdomain-6 192.168.1.38:80 check
What we got as a result:
- ssl . , ssl .
- ( ) .
- .
- , . ip ( 192.168.1.150:5000) 5000 . admin .
Haproxy.
, PROXMOKS-e N - Letsencrypt, , Haproxy .
( ) c ( ) , 80 . .
, .
!
PS The reverse proxy itself is raised and it feels great on Ubuntu 18.04 which comes in Proxmox templates. At first, I ran it in a full-fledged virtual machine mode, but this decision did not justify itself as it consumed a fair amount of processor and other resources of the host machine. With the transfer of the proxy server to the LXC container, resource consumption has dropped to almost a couple of percent of the host machine's resources and we can say that it does not consume anything.