内网搭建 GitLab , 通过 nginx 通到外网遇到问题

2015-11-13 09:20:51 +08:00
 cxq

公司内网有一台服务器已经搭建好了 GitLab

现在想通过一台连通外网的服务器 nginx 做代理 连接到这台内网
在 nginx 上配置如下

GitLab

location /gitlab {
proxy_pass http://192.168.22.188:8888;
proxy_redirect default;
}

外网通过 http://xxx.xxx.xxx.xxx/gitlab
结果首页是可以打开, 但是所有的 css 都没有了。

另外只要登录, 就自动重定向成了
http://xxx.xxx.xxx.xxx/dashboard

导致除了首页 其他所有页面都无法打开?

怎么配置 nginx 才能 css 问题 和 错误重定向问题?

15854 次点击
所在节点    git
26 条回复
debiansid
2015-11-13 09:55:54 +08:00
oott123
2015-11-13 10:25:16 +08:00
最好不要放到二级目录去
powergx
2015-11-13 11:05:12 +08:00
为什么不用耳机域名呢
beneo
2015-11-13 11:10:20 +08:00
gitlab 本身是自带 nginx 的,你要关闭原来那个,然后在自己的 nginx 上配上 passenger 什么的

总之,你文档没读 -_-!!!
cxq
2015-11-13 11:52:16 +08:00
@beneo 哦 你好像误会了。 是因为公司有一台统一的服务器搭了 nginx 是互联网入口. GitLab 是搭在内网的一台设备上的。 所以跟 GitLab 的自带的 nginx 没什么关系吧 应该。

好像上面几位也误会了。
cxq
2015-11-13 11:54:14 +08:00
@powergx 因为用 Omnibus 搭的。 配置 external_url 时候加二级域名是不能启动的。 这个我也搜了很久 没找到解决办法。
cszchen
2015-11-13 13:04:38 +08:00
gitlab 我也试过,不想用自带的 nginx , mysql 等,因为服务器上已经有这些服务了,结果折腾了好久也没搞定。换了 gogs ,非常简单,不过功能应该没有 gitlab 强大,但是自用足够了。
orzfly
2015-11-13 13:10:07 +08:00
Sofia
2015-11-13 13:10:11 +08:00
@cxq 二级域名不能启动是怎么回事?我用的就是二级域名没有问题啊
orzfly
2015-11-13 13:10:53 +08:00
https://github.com/gitlabhq/gitlabhq/blob/master/config/application.rb#L55


# Relative url support
# Uncomment and customize the last line to run in a non-root path
# WARNING: We recommend creating a FQDN to host GitLab in a root path instead of this.
# Note that following settings need to be changed for this to work.
# 1) In your application.rb file: config.relative_url_root = "/gitlab"
# 2) In your gitlab.yml file: relative_url_root: /gitlab
# 3) In your unicorn.rb: ENV['RAILS_RELATIVE_URL_ROOT'] = "/gitlab"
# 4) In ../gitlab-shell/config.yml: gitlab_url: "http://127.0.0.1/gitlab"
# 5) In lib/support/nginx/gitlab : do not use asset gzipping, remove block starting with "location ~ ^/(assets)/"
#
# To update the path, run: sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
#
# config.relative_url_root = "/gitlab"
lhbc
2015-11-13 13:13:34 +08:00
把某个目录反代到后端的根目录
一般都是有问题的
我看了下公司的 gitlab ,用的都是
<link href="/assets/application-b6b8b78ea4c3735483f6100ef977bb15.css" media="all" rel="stylesheet" />
<link href="/assets/print-47fe51cdf70398e5e54b544e0f5cc718.css" media="print" rel="stylesheet" />
<script src="/assets/application-225958ece19ac21c75cc49ae0d2719ec.js"></script>
这样的绝对路径

这样反代肯定是有问题的

建议修改 gitlab 的根目录为 /gitlab
然后在前端反代 /gitlab 目录就正常了
cxq
2015-11-13 13:44:28 +08:00
@Sofia 哦 看错了 我以为你指的是 Relative url 。 现在的外网出口,没有域名也。
cevincheung
2015-11-13 13:44:54 +08:00
用 gogs
jarlyyn
2015-11-13 13:48:26 +08:00
用 docker 解决?
jarlyyn
2015-11-13 13:52:38 +08:00
Omnibus 版本我也用过,反代的时候把我搞得欲仙欲死的。

还是用 docker 版本好,不用考虑太多

下载公司跑的就是 docker 版本的。
cxq
2015-11-13 13:52:53 +08:00
@orzfly 恩,谢谢 我来试试这个
cxq
2015-11-13 13:56:00 +08:00
@jarlyyn 这个好,我之前都不知道有 docker 版本的, 我也来试试看 谢谢
HentaiMew
2015-11-13 13:57:47 +08:00
gitlab 有 nginx 的配置文件,你需要手动修改域名。。。。
cxq
2015-11-13 14:01:33 +08:00
@HentaiMew 好像直接改 reconfigure 的时候会被抹掉的。
HentaiMew
2015-11-13 14:05:21 +08:00
@cxq 不会啊,你需要用命令让 gitlab 重新 reload 配置。假如你之前就绑定过域名,想换域名的话,光改 DNS 解析是没用的,因为仓库的域名还是原来的。 gitlab 有一大堆配置,包括域名、端口等等等等。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/235833

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX