gitlab用ngxin反向代理
修改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
重新加载配置
gitlab-ctl reconfigure
浏览器访问是否成功
http://gitlab.py-php.cn:8092
配置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端口)
遇到的问题
如果我们没登陆gitlab,访问:http://gitlab.py-php.cn:8030,就会跳转到http://gitlab.py-php.cn/users/sign_in,发现跳转后8030端口没了。
跳转的页面
我们只需打开/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端口