gpt4 book ai didi

docker - gitlab docker nginx反向代理到子路径

转载 作者:行者123 更新时间:2023-12-02 20:46:19 24 4
gpt4 key购买 nike

我正在尝试将nginx设置为反向代理,以将apps.mycompany.com/gitlab路由到与nginx在同一服务器上运行的gitlab docker容器:

Nginx配置具有:

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

第一个http调用 apps.mycompany.com/gitlab进行得很顺利,但html内的所有href基本上(例如 href:"/assets/...")仍路由到 apps.mycompany.com/assets/...而不是 apps.mycompany.com/gitlab/assets/...
因此没有找到 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 配置。

如果您的GitLab版本为 8.5 或更高版本,请根据您的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(我强烈推荐 强烈推荐),则可以向 external_url命令添加 docker run选项,并执行以下示例:
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
您可以在 official documentation中找到有关GitLab配置的更多详细信息。

我建议您还检查docker部署 official documentation中的GitLab。

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

关于docker - gitlab docker nginx反向代理到子路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53291360/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com