docker-archive / dockercloud-haproxy

HAproxy image that autoreconfigures itself when used in Docker Cloud
https://cloud.docker.com/
652 stars 181 forks source link

Exclude matching path from VIRTUAL_HOST #173

Closed santiagopoli closed 7 years ago

santiagopoli commented 7 years ago

Hi,

I have a swarm cluster with a service (service1) listening on port 8080 and a dockercloud-haproxy listening on port 80.

I've added the VIRTUAL_HOST variable in the service1 configuration (VIRTUAL_HOST=*/service1).

The problem I'm facing is that the proxy is redirecting requests in the form of { examplehost/service1 -> examplehost:8080/service1 }, but I want to achieve something like { examplehost/service1 -> examplehost:8080 }

I assume this MUST be possible, because I think is the most common use case. For example I'm creating a service that uses the bargenson/docker-swarm-visualizer image, and I want to have access to it by doing something like http://myhost.com/visualizer rather than http://myhost.com:8080

The relevant part in the docker-compose.yml for this scenario is:

version: '3'

services:

  lb:
    image: dockercloud/haproxy:latest
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - '80:80'
    networks:
      - proxy
    deploy:
      placement:
        constraints:
          - node.role == manager

  dashboard:
    image: bargenson/docker-swarm-visualizer:latest
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - '8080:8080'
    networks:
      - proxy
    environment:
      - VIRTUAL_HOST=*/dashboard
      - SERVICE_PORTS=8080
    deploy:
      placement:
        constraints:
          - node.role == manager

[...]

Thanks in advance!

dominikhahn commented 7 years ago

@santiagopoli you could use reqirep

santiagopoli commented 7 years ago

Can you provide an example of how to do it in the yml? Do I have to put it in the "OPTION" environment variable?

tifayuki commented 7 years ago

@santiagopoli

You can either use EXTRA_FRONTEND_SETTINGS_<PORT> or EXTRA_SETTINGS to set the reqrep

For example: -e "EXTRA_FRONTEND_SETTINGS_8080=reqrep ^([^\ :]*)\ /service1/(.*) \1\ /\2"