Nginx反向代理:使用jwilder / nginx-proxy为gitlab容器设置正确的端口

时间:2017-10-18 10:47:52

标签: docker nginx proxy gitlab jwilder-nginx-proxy

我需要使用nginx反向代理。因此,我使用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`错误。

我需要一些帮助来为此docker容器设置正确的端口

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

在我切换到nginx反向代理之前,我使用了这个docker-compose设置,它正在运行。而且,我并没有因为“转换”而产生的差异或错误。此

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'

1 个答案:

答案 0 :(得分:2)

您应该在您的环境中设置VIRTUAL_PORT: 80

代理实际上是在尝试将80端口重定向到SSH端口。

要在jwilderproxy中使用SSL,您可以查看here

例如,我使用它。

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