Hi guys, this is my first post so I want to say hello to everybody. This is my problem. I have two web applications (tomcat 7.0.63) running with docker in two different containers (using docker-compose). Another container contains an instance of haproxy.
This is the docker-compose.yml configuration:
services:
haproxy:
build: haproxy
container_name: haproxy
volumes:
- ./haproxy/conf/:/usr/local/etc/haproxy/
- ./haproxy/ssl/:/etc/ssl/xip.io/
ports:
- “80:80”
- “443:443”
web1:
build: web1
container_name: web1
ports:
- “8080:8080”
depends_on:
- haproxy
web2:
build: web2
container_name: web2
ports:
- “8081:8081”
depends_on:
- haproxy
version: ‘2’
And this is my haproxy configuration file:
global
log 127.0.0.1 local2
maxconn 4096
#chroot /usr/share/haproxy
tune.ssl.cachesize 0
tune.ssl.lifetime 600
tune.ssl.default-dh-param 2048
daemon
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 600s
timeout server 600s
timeout http-keep-alive 10s
timeout check 10s
maxconn 4096
timeout connect 5000
timeout client 50000
timeout server 50000
stats enable
frontend http-in
bind *:80 #ssl crt /etc/ssl/xip.io/xip.io.pem
bind *:443 ssl crt /etc/ssl/xip.io/xip.io.pem
mode http
reqadd X-Forwarded-Proto:\ http
option forwardfor
Add CORS headers when Origin header is present
capture request header origin len 128
http-response add-header Access-Control-Allow-Origin %[capture.req.hdr(0)] if { capture.req.hdr(0) -m found }
rspadd Access-Control-Allow-Methods:\ GET,\ HEAD,\ OPTIONS,\ POST,\ PUT if { capture.req.hdr(0) -m found }
rspadd Access-Control-Allow-Credentials:\ true if { capture.req.hdr(0) -m found }
rspadd Access-Control-Allow-Headers:\ Origin,\ Accept,\ X-Requested-With,\ Content-Type,\ Access-Control-Request-Method,\ Access-Control-Request-Headers,\ Authorization if { capture.req.hdr(0) -m found }
use_backend is_web1 if { path_beg /web1 }
use_backend is_web2 if { path_beg /web2 }
backend is_web1
mode http
balance roundrobin
option forwardfor
cookie JSESSIONID prefix nocache
server web1 172.17.0.1:8080/web1 check cookie web1 inter 2s fastinter 500ms downinter 2s
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
backend is_web2
mode http
balance roundrobin
option forwardfor
cookie JSESSIONID prefix nocache
server web2 172.17.0.1:8081/web2 check cookie web2 inter 2s fastinter 500ms downinter 2s
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
In order to redirect users to the correct web app checking if is /web1 or /web2. Everythings works fine.
Now I want to serve static content. This static pages are in the path /var/www/html, but I don’t know how to modify my haproxy configuration. Can anyone help me?
Thanks