AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1047390
Accepted
Noel Nemeth
Noel Nemeth
Asked: 2020-12-24 18:34:40 +0800 CST2020-12-24 18:34:40 +0800 CST 2020-12-24 18:34:40 +0800 CST

无法从容器外部访问在 Docker 中运行的 GitLab 页面

  • 772

我有一个在 docker 中运行的 GitLab 实例。GitLab 工作正常,但我无法访问GitLab Pages。

设置

概述

           +------------+
Request+-->+ Cloudflare |
           +-----+------+
                 |
                 v       +---------+
               Nginx+--->+Docker   |
                         |  +------+
                         |  |GitLab|
                         +---------+

问题是 Nginx 无法将请求传递给 GitLab Pages 服务器(请注意 GitLab 它自己工作)。
Nginx 错误日志条目

[error] 14932#14932: *30505 connect() failed (111: Connection refused) while connecting to upstream, [...]

码头工人

image: gitlab/gitlab-ce
version: 13.7.1 (latest)
ip: 172.17.0.7 (dynamic)
published ports:
    172.17.0.1:8080 -> 80
    172.17.0.1:8090 -> 8090

Nginx

页面的服务器条目

server {
        listen 80 default_server;
        listen 443 default_server;
        server_name _;
        
        location / {
                proxy_pass      http://172.17.0.1:8090;
        }
}

GitLab

grep -v '^#|^$' gitlab.rb 1

nginx['listen_port'] = 80
nginx['listen_https'] = false
pages_external_url "http://pages.example.com/"
gitlab_pages['enable'] = true
gitlab_pages['external_http'] = []
gitlab_pages['listen_proxy'] = "localhost:8090"
gitlab_pages['inplace_chroot'] = true
gitlab_pages['metrics_address'] = ":9235"
pages_nginx['enable'] = true
pages_nginx['listen_https'] = false
pages_nginx['redirect_http_to_https'] = false

还尝试了绝对最小配置,仅定义pages_external_urland gitlab_pages['enable']。

追查问题

  1. 对 pages.example.com 的请求失败,来自 CF 的 502(错误网关)
  2. 查看Nginx日志,发现上面提到的日志条目
  3. 从主机向容器发出多个请求
    1. # curl 172.17.0.1:8090 -> curl: (7) Failed to connect to 172.17.0.1 port 8090: Connection refused
    2. # curl 172.17.0.7:8090 -> curl: (7) Failed to connect to 172.17.0.7 port 8090: Connection refused
  4. 从容器发出请求
    # curl localhost:8090 -> 404 error page

据此,我假设某些东西正在阻止 8090 (GitLab Pages)的传入流量,但对 80 (GitLab)的请求已成功完成。我花了几天时间在谷歌上搜索这个问题,但我找不到任何东西。


1截断;已删除 SMTP、LDAP 和omniauth 设置
nginx docker gitlab
  • 1 1 个回答
  • 1393 Views

1 个回答

  • Voted
  1. Best Answer
    Noel Nemeth
    2020-12-27T13:58:15+08:002020-12-27T13:58:15+08:00

    经过数小时搜索错误的事情后,才找到了我的问题的原因(但稍后会详细介绍)。

    TL;博士

    我不得不改变gitlab_pages['listen_proxy']值来监听每个接口,所以它看起来像这样:

    gitlab_pages['listen_proxy'] = "0.0.0.0:8090"
    

    详细的

    我正在使用与 gitlab 页面相关的关键字搜索这个问题,刚才我觉得我可能需要跳出框框思考,如果这是一个更普遍的问题,甚至与 GitLab 页面无关怎么办。在第一次谷歌搜索后,我发现了一篇关于这个的好文章。

    我收到“连接被拒绝”消息,因为端口 8090 上没有任何东西在监听,因为localhost它指的是环回地址,即127.0.0.1,但是暴露的端口被转发给容器的 IP,在我的情况下,它是一个动态 IP,写问题时是172.17.0.7。所以解决方案是监听每个可能0.0.0.0用作 IP 地址的接口。

    将问题和解决方案形象化的两张图

    (来自上述文章的数字,但稍作修改以更好地匹配问题,并且在使用 force-darkmode 时仅将其变为文本以提高可读性)
    使用时localhost:8090:

       Request      +--------------------------------------+
          +         | Default network namespace            |
          |         |                                      |
          |         |               +-------+              |
          v         |        +----->+ Nginx +------+       |
    +-----+------+  |        |      +-------+      |       |
    | Cloudflare |  |        |                     |       |
    +-----+------+  |        |                     v       |
          |         +--------+-----------+-+-------+-------+
          |         | Physical interface | | Docker bridge |
          +-------->+ 10.0.0.1           | | 172.17.0.1    |
                    +--------------------+ +-------+-------+
                                                   |
                                                   |
                                                   v
                                           +-------+-------+
                                           | Docker bridge |
                                           | 172.17.0.7    |
                     +-------+-----------+-+---------------+
                     |       | Loopback  |                 |
                     |       | 127.0.0.1 |                 |
                     |       +-----+-----+                 |
                     |             |                       |
                     |             |      +--------------+ |
                     |             +----->+ Pages server | |
                     |                    +--------------+ |
                     |GitLab's Network namespace           |
                     +-------------------------------------+
    

    监听每个接口,使用0.0.0.0:8090:

       Request      +--------------------------------------+
          +         | Default network namespace            |
          |         |                                      |
          |         |               +-------+              |
          v         |        +----->+ Nginx +------+       |
    +-----+------+  |        |      +-------+      |       |
    | Cloudflare |  |        |                     |       |
    +-----+------+  |        |                     v       |
          |         +--------+-----------+-+-------+-------+
          |         | Physical interface | | Docker bridge |
          +-------->+ 10.0.0.1           | | 172.17.0.1    |
                    +--------------------+ +-------+-------+
                                                   |
                                                   |
                                                   v
                                           +-------+-------+
                                           | Docker bridge |
                                           | 172.17.0.7    |
                     +-------+-----------+-+-------+-------+
                     |       | Loopback  |         |       |
                     |       | 127.0.0.1 |         |       |
                     |       +-----+-----+         |       |
                     |             |               v       |
                     |             |      +--------+-----+ |
                     |             +----->+ Pages server | |
                     |                    +--------------+ |
                     |GitLab's Network namespace           |
                     +-------------------------------------+
    
    • 0

相关问题

  • Gzip 与反向代理缓存

  • nginx 作为代理的行为

  • Nginx 学习资源 [关闭]

  • 提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 在 Apache、LightTPD 和 Nginx Web 服务器上提供 PHP 5.x 应用程序的现状?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve