问题 运行 Docker 中未绑定 Nginx 和 Wordpress 的 Gitlab

Problem running Gitlab with unbound Nginx and Wordpress in Docker

我正在尝试在 Docker 中将 Gitlab 和 Wordpress 与 Nginx 一起设置。我只能发布端口 80 和 443,这就是为什么我想使用未绑定的 Nginx 将 docker 中发布的端口映射到(子)URL。 我可以使用 ssl 通过域名访问 Wordpress,也可以使用 suburls 访问其他 docker-container,但我无法访问 Gitlab。我已经尝试了多个 Nginx 和 Gitlab 设置,例如打开/关闭 Gitlabs 自己的 Nginx 和 gitlab.rbexternal_url 的不同值,但我只在使用以下设置的过程中进行了一半。但是,每次我尝试登录时,我都会被重定向到 wordpress,其中 url 类似于 my.domain.com/users/sign_in

这是我的设置:

version: '3.6'
services:
  git:
    image: gitlab/gitlab-ce:14.10.0-ce.0
    restart: unless-stopped
    container_name: gitlab
    hostname: 'my.domain.com'
    environment:
      GITLAB_OMNIBUS_CONFIG: |
         gitlab_rails['gitlab_shell_ssh_port'] = 2224
         external_url 'http://127.0.0.1:8929/'
    ports:
      - "8929:80"
      - "2224:22"
    shm_size: '256m'
server {
  listen 80;
  listen [::]:80;

  server_name my.domain.com www.my.domain.com;


  location ~ /.well-known/acme-challenge {
    allow all;
    root /var/www/certbot;
  }


  location / {
    rewrite ^ https://$host$request_uri? permanent;
  }
}
server {
  listen 443 ssl http2;
  listen [::]:443 ssl http2;

  root /var/www/html;

  index index.php;

  server_name my.domain.com www.my.domain.com;

  server_tokens off;

  ssl_certificate /etc/nginx/ssl/live/my.domain.com/fullchain.pem;
  ssl_certificate_key /etc/nginx/ssl/live/my.domain.com/privkey.pem;


  location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ /index.php?$args;
  }

# WORDPRESS
  # pass the PHP scripts to FastCGI server listening on wordpress:9000
  location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass wordpress:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param SCRIPT_NAME $fastcgi_script_name;
  }
# GITLAB
  location /gitlab/ {
    gzip                    off;
    proxy_pass http://127.0.0.1:8929/;
  }
}

目标应该是这样的:

my.domain.com                 -> Wordpress        -> (directly setup together with nginx, therefore no ports published by wordpress-service)
my.domain.com/gitlab          -> Gitlab           -> Docker-Port: 8929:80, 2224:22
my.domain.com/something-else  -> Something-Else   -> Docker-Port: 9000:9000

在删除所有内容并进行新设置后,我实际上得到了它 运行,设置略有不同:

docker-compose Gitlab:

version: '3.6'
services:
  git:
    image: gitlab/gitlab-ce:14.10.0-ce.0
    restart: unless-stopped
    container_name: gitlab
    hostname: 'my.domain.com'
    environment:
      GITLAB_OMNIBUS_CONFIG: |
         gitlab_rails['gitlab_shell_ssh_port'] = 2224
         external_url 'http://<host-ip-address>:<docker-gitlab-port>/gitlab/'
    ports:
      - "8929:8929" #doesn't work with 8929:80; no clue why though
      - "2224:2224"
    volumes:
      - /opt/gitlab/config:/etc/gitlab:rw
      - /opt/gitlab/data:/var/opt/gitlab:rw
    shm_size: '256m'

nginx.conf 变化

location /gitlab/ {
    root /home/git/gitlab/public;
    
    proxy_http_version 1.1;
    proxy_pass http://<host-ip-address>:<docker-gitlab-port>/gitlab/;

    gzip                    off;

    #proxy_set_header    Host                $http_host; ##This one crashes everything (?)
    proxy_set_header    X-Real-IP           $remote_addr;
    proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
  }

gitlab.rb

external_url 'http://<host-ip-address>:<docker-gitlab-port>/gitlab/'