内网搭建 GitLab , 通过 nginx 通到外网遇到问题 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
git
Pro Git
Atlassian Git Tutorial
Pro Git 简体中文翻译
GitX
cxq
V2EX    git

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

  •  
  •   cxq 2015-11-13 09:20:51 +08:00 16508 次点击
    这是一个创建于 3625 天前的主题,其中的信息可能已经有所发展或是发生改变。

    公司内网有一台服务器已经搭建好了 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 问题 和 错误重定向问题?

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

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

    好像上面几位也误会了。
    cxq
        6
    cxq  
    OP
       2015-11-13 11:54:14 +08:00
    @powergx 因为用 Omnibus 搭的。 配置 external_url 时候加二级域名是不能启动的。 这个我也搜了很久 没找到解决办法。
    cszchen
        7
    cszchen  
       2015-11-13 13:04:38 +08:00
    gitlab 我也试过,不想用自带的 nginx , mysql 等,因为服务器上已经有这些服务了,结果折腾了好久也没搞定。换了 gogs ,非常简单,不过功能应该没有 gitlab 强大,但是自用足够了。
    Sofia
        9
    Sofia  
       2015-11-13 13:10:11 +08:00
    @cxq 二级域名不能启动是怎么回事?我用的就是二级域名没有问题啊
    orzfly
        10
    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
        11
    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="http://www.v2ex.com/assets/application-225958ece19ac21c75cc49ae0d2719ec.js"></script>
    这样的绝对路径

    这样反代肯定是有问题的

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

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

    下载公司跑的就是 docker 版本的。
    cxq
        16
    cxq  
    OP
       2015-11-13 13:52:53 +08:00
    @orzfly 恩,谢谢 我来试试这个
    cxq
        17
    cxq  
    OP
       2015-11-13 13:56:00 +08:00
    @jarlyyn 这个好,我之前都不知道有 docker 版本的, 我也来试试看 谢谢
    HentaiMew
        18
    HentaiMew  
       2015-11-13 13:57:47 +08:00
    gitlab 有 nginx 的配置文件,你需要手动修改域名。。。。
    cxq
        19
    cxq  
    OP
       2015-11-13 14:01:33 +08:00
    @HentaiMew 好像直接改 reconfigure 的时候会被抹掉的。
    HentaiMew
        20
    HentaiMew  
       2015-11-13 14:05:21 +08:00
    @cxq 不会啊,你需要用命令让 gitlab 重新 reload 配置。假如你之前就绑定过域名,想换域名的话,光改 DNS 解析是没用的,因为仓库的域名还是原来的。 gitlab 有一大堆配置,包括域名、端口等等等等。
    qqjt
        21
    qqjt  
       2015-11-13 14:06:52 +08:00
    server
    {
    listen 80;
    server_name xxx.xxx;
    location / {
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://127.0.0.1:233;
    }
    access_log /var/log/nginx/gitlab-access.log;
    }

    我是这么配的, gitlab 地址是 http://127.0.0.1:233
    powergx
        22
    powergx  
       2015-11-13 14:25:03 +08:00
    @jarlyyn 我也 omnibus 装的, external 一改, nginx 反代, 爽 yy 完全没问题
    jarlyyn
        23
    jarlyyn  
       2015-11-13 14:33:04 +08:00
    @powergx

    走 https 了么?
    cxq
        24
    cxq  
    OP
       2015-11-13 15:15:40 +08:00
    @powergx 求指导 是因为用了 Relative url 吗?
    powergx
        25
    powergx  
       2015-11-13 20:38:35 +08:00 via iPhone
    @jarlyyn external url 写 https ://git.xxx.com 就可以了啊
    beling
        26
    beling  
       2015-11-14 11:07:13 +08:00
    不想用自带的 nginx , mysql
    那你自己编译装啊 可以选择 nginx , Apache , mysql , pgsql
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     5616 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 31ms UTC 06:31 PVG 14:31 LAX 23:31 JFK 02:31
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86