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

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

我需要使用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 a502 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 设置,它正在工作。而且我不明白'converting'这个我犯的错误。

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'

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

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

要将 SSL 与 jwilderproxy 一起使用,您可以查看 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