Cara mempublikasikan multiple domain, satu IP public dengan HAProxy. | Blog Bai Rahmat

Cara mempublikasikan multiple domain, satu IP public dengan HAProxy.

Sering kali kita membutuhkan untuk menerbitkan banyak situs website dari jaringan internal, tetapi hanya ada satu alamat IP publik yang tersedia. Bagaimana ini bisa dilakukan dengan mudah ? HAProxy dapat membantu dengan hal tersebut.


Keterangan IP ( gambar diatas )
Virtual Machine - VM HAProxy : 10.10.1.3
Virtual Machine - VM Webserver 1 : 10.10.1.4
Virtual Machine - VM Webserver 2 : 10.10.1.5
Virtual Machine - VM Webserver 3 : 10.10.1.6

Contoh, kita memiliki 3 domain/subdomain yang terpointing ke alamat satu IP public: 
- bairahmat.my.id 
- pihole.bairahmat.my.id 
- hotspot.bairahmat.my.id

Yang kita butuhkan : 
- Satu IP Public 
- Mikrotik ( sudah tertanam IP Public di ether-internet) 
- Haproxy ( VM Proxmox ) Cara install HAProxy bisa lihat di Cara Install HAProxy

Contoh Konfigurasi NAT di Mikrotik
/ip firewall nat
add action=dst-nat chain=dstnat comment="To Haproxy" dst-address=(IP Public ) dst-port=80,8080 protocol=tcp to-addresses=IP HAProxy
Contoh konfigurasi di HAProxy:
Menambahkan konfigurasi Haproxy dengan perintah :
nano /etc/haproxy/haproxy.cfg
Contoh Konfigurasi haproxy.cfg
global
        log 127.0.0.1   local0
        log 127.0.0.1   local1 notice
        chroot /var/lib/haproxy
        stats socket /run/haproxy/admin.sock mode 660 level admin
        stats timeout 30s
        user haproxy
        group haproxy
        daemon

        # Default SSL material locations
        ca-base /etc/ssl/certs
        crt-base /etc/ssl/private
        ssl-server-verify required
        tune.maxrewrite 4096
        tune.http.maxhdr 2024

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        option forwardfor
        retries 3
        redispatch
        maxconn 2000
        clitimeout 2s
        srvtimeout 3s
        timeout connect 5000
        timeout client  50000
        timeout server  50000
        errorfile 400 /etc/haproxy/errors/400.http
        errorfile 403 /etc/haproxy/errors/403.http
        errorfile 408 /etc/haproxy/errors/408.http
        errorfile 500 /etc/haproxy/errors/500.http
        errorfile 502 /etc/haproxy/errors/502.http
        errorfile 503 /etc/haproxy/errors/503.http
        errorfile 504 /etc/haproxy/errors/504.http
       
        stats enable
        stats auth admin:admin
        stats uri /stats

resolvers dns
  nameserver public-0 10.10.1.1:53
  hold valid 1s

frontend http
        bind *:80
        bind *:8080
        reqadd X-Forwarded-Proto:\ http
        mode http

        acl web1_url hdr_dom(host) -i bairahmat.my.id
        acl web2_url hdr_dom(host) -i pihole.bairahmat.my.id
        acl web3_url hdr_dom(host) -i hotspot.bairahmat.my.id

        use_backend WEB-1 if web1_url   
        use_backend WEB-2 if web2_url
        use_backend WEB-3 if web3_url

backend WEB-1
        http-request set-header X-Forwarded-Port %[dst_port]
        rspadd Strict-Transport-Security:\ max-age=15768000;\ includeSubDomains

        balance roundrobin
        option forwardfor
        cookie JSESSIONID prefix
        server web-1 10.10.1.4:80 check

backend WEB-2
        http-request set-header X-Forwarded-Port %[dst_port]
        rspadd Strict-Transport-Security:\ max-age=15768000;\ includeSubDomains

        balance roundrobin
        option forwardfor
        cookie JSESSIONID prefix
        server web-2 10.10.1.5:80 check

backend WEB-3
        http-request set-header X-Forwarded-Port %[dst_port]
        rspadd Strict-Transport-Security:\ max-age=15768000;\ includeSubDomains

        balance roundrobin
        option forwardfor
        cookie JSESSIONID prefix
        server web-3 10.10.1.6:80 check
Silahkan mencoba, semoga berhasil ...



Subscribe to receive free email updates:

0 Response to "Cara mempublikasikan multiple domain, satu IP public dengan HAProxy."

Post a Comment