Search code examples
apachedockerdocker-composehaproxy

Docker haproxy issue with web path


I am trying to get haproxy to connect to the webserver using localhost/path

My current setup is as folows:

HAproxy_test
│   docker-compose.yml
│
├───haproxy
│       Dockerfile
│       haproxy.cfg
│
└───website
        index.php

docker-compose.yml:

version: '3'

services:

  website1:
    image: php:apache
    hostname: website_1
    volumes: 
      - ./website:/var/www/html
    ports:
      - 8080:80

  haproxy:
    build: ./haproxy
    ports:
      - 80:80
    depends_on:
      - website1

haproxy/Dockerfile:

FROM haproxy

COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg

haproxy/haproxy.cfg:

global
    maxconn 5000

defaults
    mode http
    timeout connect 5s
    timeout client 5s
    timeout server 5s

frontend http_in
    bind *:80

    acl has_web1 path_beg -i /web1 
    use_backend http_out if has_web1

    default_backend http_out

backend http_out
    server web1 website1:80 check

Using docker-compose up --build everything comes up fine. If type in localhost or localhost:8080 it takes me to the website and everything is great BUT if i try localhost/web1 I get a 404 Not Found

enter image description here

HOWEVER, if I change my dockder-compose.yml for example to use image: dockercloud/hello-world instead of image: php:apache the localhost/web1 works just fine

enter image description here

Am I missing some configuration in apache that is pressent in the dockercloud/hello-world image?


Solution

  • It seems to me like your redirect rule in NGINX is working, but the apache server is receiving a request for the path WWWROOT/web1, so Apache is looking for the file or directory at path WWWROOT/web1 which is non-existent, thus giving a 404. You could test by adding the sub directory web1 with basic index.html, and check if that gets served.