简体   繁体   中英

Nginx reverse proxy: Set correct ports using jwilder/nginx-proxy for gitlab container

I need to use a nginx reverse proxy. Therefore I use jwilder/nginx-proxy. Also I'm using gitLab as a docker container. So I came up with this docker-compose file, but accessing ci.server.com gives me a jwilder/nginx-proxy. Also I'm using gitLab as a docker container. So I came up with this docker-compose file, but accessing ci.server.com gives me a jwilder/nginx-proxy. Also I'm using gitLab as a docker container. So I came up with this docker-compose file, but accessing ci.server.com gives me a 502 Bad Gateway` error.

I need some help to setup the correct ports for this docker container

version: '3.3'
services:
  nginx:
    container_name: 'nginx'
    image: jwilder/nginx-proxy:alpine
    restart: 'always'
    ports:
      - 80:80
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro

  gitlab:
    container_name: gitlab
    image: 'gitlab/gitlab-ce:10.0.2-ce.0'
    restart: always
    hostname: 'ci.server.com'
    ports:
      - '50022:22'
    volumes:
      - '/opt/gitlab/config:/etc/gitlab'
      - '/opt/gitlab/logs:/var/log/gitlab'
      - '/opt/gitlab/data:/var/opt/gitlab'
      - '/opt/gitlab/secret:/secret/gitlab/backups'
      - '/etc/letsencrypt:/etc/letsencrypt'
    environment:
      VIRTUAL_HOST: ci.server.com
      VIRTUAL_PORT: 50022

Before I switched to nginx reverse proxy I used this docker-compose setup, which was working. And I don't get the difference or the mistake I made by 'converting' this.

old

version: '3.3'
services:
  nginx:
    container_name: 'nginx'
    image: 'nginx:1.13.5'
    restart: 'always'
    ports:
      - '80:80'
      - '443:443'
    volumes:
      - '/opt/nginx/conf.d:/etc/nginx/conf.d:ro'
      - '/opt/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro'
      - '/etc/letsencrypt:/etc/letsencrypt'
    links:
      - 'gitlab'

  gitlab:
    container_name: gitlab
    image: 'gitlab/gitlab-ce:10.0.2-ce.0'
    restart: always
    hostname: 'ci.server.com'
    ports:
      - '50022:22'
    volumes:
      - '/opt/gitlab/config:/etc/gitlab'
      - '/opt/gitlab/logs:/var/log/gitlab'
      - '/opt/gitlab/data:/var/opt/gitlab'
      - '/opt/gitlab/secret:/secret/gitlab/backups'
      - '/etc/letsencrypt:/etc/letsencrypt'

You should set VIRTUAL_PORT: 80 in your environment.

The proxy is actually trying to redirect the 80 port to the SSH port.

To use SSL with jwilderproxy you can look here

for example, I use this.

version: '3/3' services: gitlab: container_name: gitlab image: 'gitlab/gitlab-ce:10.0.2-ce.0' restart: always hostname: 'ci.server.com' ports: - '50022:22' volumes: - '/opt/gitlab/config:/etc/gitlab' - '/opt/gitlab/logs:/var/log/gitlab' - '/opt/gitlab/data:/var/opt/gitlab' - '/opt/gitlab/secret:/secret/gitlab/backups' - '/etc/letsencrypt:/etc/letsencrypt' environment: - VIRTUAL_HOST=ci.server.com - VIRTUAL_PORT=80 - LETSENCRYPT_HOST=ci.server.com - LETSENCRYPT_EMAIL=youremail

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM