计算机学习

您现在的位置是:首页 > git > gitlab > 正文

gitlab

gitlab用ngxin反向代理

hhb2022-03-23gitlab465
修改GITLAB配置参数修改/etc/gitlab/gitlab.rb配置参数修改仓库的url,此处的url不需要带上端口,因为是通过外部Nginx反向代理到指定的端口,配置的域名与外部访问的域名一致

修改GITLAB配置参数

  • 修改/etc/gitlab/gitlab.rb配置参数
    修改仓库的url,此处的url不需要带上端口,因为是通过外部Nginx反向代理到指定的端口,配置的域名与外部访问的域名一致

 external_url  'http://gitlab.py-php.cn'

       修改Gitlab内部Nginx端口:8092

   nginx['listen_port'] = 8092

     9ec251403fff20e5b2a3ba7e4d9ae4ad_wpsA2CE.tmp.jpg












配置nginx反向代理

gitlab.py-php.cn 是我的子域名

  • nginx配置

upstream  git{
    # 域名对应 gitlab配置中的 external_url
    # 端口对应 gitlab 配置中的 nginx['listen_port']
    server  gitlab.py-php.cn:8092;
}
server{
    listen 8030;
    # 此域名是提供给最终用户的访问地址
    server_name py-phptttttt.cn;#server_name任意填都行

    location / {
        # 这个大小的设置非常重要,如果 git 版本库里面有大文件,设置的太小,文件push 会失败,根据情况调整
        client_max_body_size 50m;
        proxy_redirect off;
        #以下确保 gitlab中项目的 url 是域名而不是 http://git,不可缺少
        proxy_set_header Host $host:$proxy_port;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        # 反向代理到 gitlab 内置的 nginx
        proxy_pass http://git;
        index index.html index.htm;
    }
}
  • 浏览器访问

http://gitlab.py-php.cn:8030,结果如下图,浏览器用8030端口就可以访问到gitlab(我们也可以把8030换成80端口)


1647969668(1).png




遇到的问题

如果我们没登陆gitlab,访问:http://gitlab.py-php.cn:8030,就会跳转到http://gitlab.py-php.cn/users/sign_in,发现跳转后8030端口没了。

1647969962.png

跳转的页面


1647970050(1).png

我们只需打开/etc/gitlab/gitlab.rb文件,把如下配置打开(默认是被注释掉的),再执行gitlab-ctl reconfigure,重新加载gitlab配置就行。

nginx['proxy_set_headers'] = {
  "Host" => "gitlab.py-php.cn:8030",
  "X-Real-IP" => "$remote_addr",
  "X-Forwarded-For" => "$proxy_add_x_forwarded_for",
#  "X-Forwarded-Proto" => "https",
#  "X-Forwarded-Ssl" => "on",
#  "Upgrade" => "$http_upgrade",
#  "Connection" => "$connection_upgrade"
}

8030就是我们上面nginx配置的端口,它是提供给用户访问的端口。如果我们nginx配置80给用户访问,这里proxy_set_headers配置就不需要打开,因为默认就是80端口



发表评论

评论列表

  • 访客(2024-07-06 14:13:39)回复取消回复

    态度决定一切,不错!http://ll0f1.xzssbl.cn/

  • 访客(2024-07-07 07:26:11)回复取消回复

    这位作者的文笔极其出色,用词精准、贴切,能够形象地传达出他的思想和情感。http://3bi.net/post/875.html/

  • 访客(2024-07-07 07:51:17)回复取消回复

    楼主该去看心理医生了!http://3bi.net/post/875.html/

  • 访客(2024-07-07 07:58:29)回复取消回复

    看帖不回帖的人就是耍流氓,我回复了!http://2ozo.bjfacx.com/

  • 访客(2024-07-07 19:51:46)回复取消回复

    楼主好聪明啊!http://6d1.tiannuojixie.com/

  • 访客(2024-07-07 21:10:31)回复取消回复

    今天怎么了,什么人都出来了!http://zs7e.netlook.cn/