5

Estoy trabajando con Docker con un compose donde tengo un apache con php, un redmine, portainer para controlar los contenedores y estoy instalando GitLab.

Mi problema viene en GitLab ya que por defecto me obliga a poner un puerto para acceder y me gustaría que fuera por una ruta, pero entiendo que cada contenedor tiene o su apache o su Nginx ya que cuanto tiro apache y php sigo pudiendo entrar en redmine y gitlab. Como puedo hacer para acceder por una ruta a GitLab he mirado el tema de los VirtualHost pero al estar en diferentes Docker no se como decirle donde tiene que buscar la información.

El principal problema es que me obliga a poner el puerto siempre cuando un usuario intenta recuperar una contraseña le llega la ruta sin el puerto o clonar un repositorio y tiene que ponerlo a mano.

un saludo y gracias.

Modifico el POST

Este es mi docker-compose completo. Soy nuevo en docker y voy aprendiendo con cada problema que aparece.

version: '2'
services:
  php:
    container_name: php
    restart: always
    image: php:7-apache
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./html:/var/www/html
      - ./certificados:/etc/ssl/certs
  gitlab:
   image: 'gitlab/gitlab-ce:latest'
   restart: always
   hostname: 'localhost'
   environment:
     GITLAB_OMNIBUS_CONFIG: |
       external_url 'http://localhost/gitlab'
       # Add any other gitlab.rb configuration here, each on its own line
   ports:
     - '32787:80'
     - '32786:443'
     - '32788:22'
   volumes:
     - './config:/etc/gitlab'
     - './logs:/var/log/gitlab'
     - './data:/var/opt/gitlab'
  redmine:
    container_name: redmine
    restart: always
    image: redmine
    ports:
      - "3000:3000"
    volumes:
      - ./redmineData:/usr/src/redmine/files
      - ./redminePlugins:/usr/src/redmine/plugins
      - ./redmineConfig/configuration.yml:/usr/src/redmine/config/configuration.yml
    environment:
      REDMINE_DB_MYSQL: xx
      REDMINE_DB_PASSWORD: xxxxxx
  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: xxxxx
      MYSQL_DATABASE: xxxx
    volumes:
      - ./mysqlData:/var/lib/mysql
  portainer:
    image: portainer/portainer
    restart: always
    ports:
      - "9000:9000"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./portainer_data:/data portainer/portainer

mi idea seria poder entrar de esta forma http://localhost/gitlab

y no con el puerto http://localhost:32787/gitlab asi funciona. El principal problema es a la hora de subir por ssh o recuperar la pass me envia el correo sin el puerto.

Un saludo.

Edit 01

docker-compose

version: '2'
services:
  nginx: 
    image: nginx:latest
    container_name: servidor_nginx
    depends_on:
      - php
      - redmine
    volumes:
      - ./virtualhost.conf:/etc/nginx/nginx.conf
    ports:
      - 80:80
      - 443:443
  php:
    container_name: php
    restart: always
    image: php:7-apache
    ports:
      - "8080:80"
    volumes:
      - ./html:/var/www/html
  redmine:
    container_name: redmine
    restart: always
    image: redmine
    ports:
      - "3000:3000"
    volumes:
      - ./redmineData:/usr/src/redmine/files
      - ./redminePlugins:/usr/src/redmine/plugins
      - ./redmineConfig/configuration.yml:/usr/src/redmine/config/configuration.yml
    environment:
      REDMINE_DB_MYSQL: db
      REDMINE_DB_PASSWORD: xxxxx
  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: xxxxx
      MYSQL_DATABASE: redmine
    volumes:
      - ./mysqlData:/var/lib/mysql
  portainer:
    image: portainer/portainer
    restart: always
    ports:
      - "9000:9000"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./portainer_data:/data portainer/portainer

virtualhost

events {

}

http {
  error_log /etc/nginx/error_log.log warn;
  client_max_body_size 20m;

  proxy_cache_path /etc/nginx/cache keys_zone=one:500m max_size=1000m;
        server {
            listen 80;
            server_name  localhost;
            location /php {
                proxy_pass         http://php:8080/;
                proxy_redirect     off;
                proxy_set_header   Host $host;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header   X-Real-IP $remote_addr;
                proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header   X-Forwarded-Host $http_host;
            }
            location /redmine {
                proxy_pass         http://redmine:3000/;
                proxy_redirect     off;
                proxy_set_header   Host $host;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header   X-Real-IP $remote_addr;
                proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header   X-Forwarded-Host $http_host;
            }

        }
    }

Cuando pruebo esta ruta:

http://localhost/redmine me da 502 Bad Gateway

3
  • Hola, podrias compartir tu compose para ayudarte. Gitlab esta tambien dentro del compose ? el 23 ago. 2019 a las 12:52
  • 1
    Creo que la solución pasa por usar nginx (por ejemplo) como proxy reverso, de modo que sea nginx el que reciba todas las conexiones http/https y, según la ruta y mediante reglas de redirección, las reenvíe al puerto correspondiente (eliminando de la url la parte de la ruta usada para distinguir entre aplicaciones)
    – abulafia
    el 4 sep. 2019 a las 14:20
  • Acabo de modificar el post. Para eso necesito añadir a mi docker-compose un nginx y hacer en este el proxy inverso?
    – Manolait
    el 4 sep. 2019 a las 14:33

1 respuesta 1

3

Agrega a tu docker-compose tu servidor nginx para que haga el proxy inverso.

Lo primero, crea tu virtualhost.conf se deberia encontrar en la raiz junto con el docker-compose.yml :

worker_processes 1;

events { worker_connections 1024; }

http {

    sendfile on;

    upstream server_redmine{
        server redmine:3000;
    }

    client_max_body_size 5M;
    server {
        listen 0.0.0.0:90;
        server_name  localhost;
        proxy_set_header Host $http_host/redmine;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_redirect    off;
        add_header Pragma "no-cache";
        add_header Cache-Control "no-cache";
        location  /redmine {
            sub_filter 'action="/'  'action="/redmine/';
            sub_filter 'href="/'  'href="/redmine/';
            sub_filter 'src="/'  'src="/redmine/';
            sub_filter_once off;
            proxy_pass  http://server_redmine/;
        }
    }
}

Donde en la linea proxy_pass debe ser configurada como: proxy_pass http://container_name:port_container

lo segundo, en tu docker-compose.yml agrega algo como:

version: '2'
services:
     nginx: 
        image: nginx:latest
        container_name: servidor_nginx
        depends_on:
          - redmine
        volumes:
          - ./virtualhost.conf:/etc/nginx/nginx.conf
        ports:
          - 90:90
          - 443:443
      redmine:
        container_name: redmine
        restart: always
        image: redmine
        ports:
          - "3000:3000"

Respuesta Modo BETA

9
  • hola, gracias por la respuesta me da el siguiente error nginx: [emerg] "server" directive is not allowed here in /etc/nginx/nginx.conf:1
    – Manolait
    el 5 sep. 2019 a las 8:21
  • Hola, ya no me da el error anterior pero no encuentra la web por la ruta: 502 Bad Gateway sigue estando accesible por el puerto y no por ruta.
    – Manolait
    el 9 sep. 2019 a las 8:01
  • acado de editar el nginx.conf, me falto agregar que el server_name y otras ediciones menores el 9 sep. 2019 a las 14:20
  • Buenas de nuevo, seguimos igual....
    – Manolait
    el 9 sep. 2019 a las 19:17
  • Edito el Post un saludo
    – Manolait
    el 9 sep. 2019 a las 20:21

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.