繁体   English   中英

gitlab docker nginx 反向代理到子路径

[英]gitlab docker nginx reverse proxy to a sub path

我想设置Nginx的反向代理路由apps.mycompany.com/gitlab到同一个服务器的nginx上运行的gitlab泊坞窗容器:

nginx 配置有:

location /gitlab/ {
    proxy_pass     http://127.0.0.1:3000/;
    proxy_redirect default;
}

第一个 http 调用apps.mycompany.com/gitlab进行得很顺利,但基本上 html 中的所有 hrefs(例如href:"/assets/..." )仍然路由到apps.mycompany.com/assets/...而不是apps.mycompany.com/gitlab/assets/...

所以没有找到资产和css文件。 呈现的页面有结构但没有样式,我什至不知道还有什么不起作用。

我不太了解 nginx 不知道我做错了什么

NGINX

在您的 nginx 配置中添加proxy_set_header选项并更改proxy_pass如下:

location /gitlab/ {
    proxy_set_header Host $http_host;
    proxy_pass http://127.0.0.1:3000/gitlab/;
}

GITLAB

您正在寻找的是 GitLab 中的相对 URL配置。

如果您有8.5或更高版本的 GitLab,请根据您的 GitLab 部署类型执行以下操作之一:

DOCKER-COMPOSE 部署

将环境变量external_url添加到您docker-compose.yml文件,示例文件:

gitlab:
    image: 'gitlab/gitlab-ce:11.5.2-ce.0'
    restart: always
    environment:
            GITLAB_OMNIBUS_CONFIG: |
                    external_url 'http://apps.mycompany.com/gitlab/'
    ports:
            - '3000:80'

然后重启 GitLab docker:

docker-compose up -d

DOCKER部署

如果您没有使用 docker-compose(我强烈推荐),那么您可以在docker run命令中添加external_url选项,示例执行:

docker run --detach --publish 3000:80 --restart always --env GITLAB_OMNIBUS_CONFIG="external_url 'http://apps.mycompany.com/gitlab/'" gitlab/gitlab-ce:11.5.2-ce.0

GitLab 配置文件更新 - 可用于各种部署

另一种方法是直接修改 GitLab 配置文件,但我建议对于独立的 GitLab 安装而不是 docker 部署。

修改/etc/gitlab/gitlab.rb GitLab 配置,将external_url值更改为以下内容:

external_url "http://apps.mycompany.com/gitlab"

在此更改之后,您必须重新配置 GitLab:

sudo gitlab-ctl reconfigure

然后重启服务:

sudo gitlab-ctl restart

您可以在官方文档中找到有关 GitLab 配置的更多详细信息。

我建议您也查看 docker 部署官方文档中的GitLab。

请注意,Omnibus GitLab 中的相对 URL 支持是实验性的,并在 8.5 版中引入(对于早期版本,您需要从源代码 - doc编译它)。

我的 https gitlab 设置:

docker-compose.yml:

web:
  image: 'gitlab/gitlab-ee:latest'
  restart: always
  hostname: 'gitlab.yourdomain.com'
  environment:
    GITLAB_OMNIBUS_CONFIG: |
      external_url 'https://gitlab.yourdomain.com'
      gitlab_rails['gitlab_shell_ssh_port'] = 9122
      nginx['enable'] = true
      nginx['listen_port'] = 9180
      nginx['listen_https'] = false
  ports:
    - '9180:9180'
    - '9122:22'
  volumes:
    - '/opt/gitlab/config:/etc/gitlab'
    - '/opt/gitlab/logs:/var/log/gitlab'
    - '/opt/gitlab/data:/var/opt/gitlab'

nginx gitlab.conf:

server {
  listen       443;
  server_name  gitlab.yourdomain.com;

  location / {
    proxy_set_header    Host                $http_host;
    proxy_set_header    X-Real-IP           $remote_addr;
    proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
    proxy_set_header    X-Forwarded-Proto   $scheme;
    proxy_pass http://127.0.0.1:9180;
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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