修改gitlab默认的nginx


前言:
本文将介绍,如何禁用gitlab自带的nginx,用已经安装的nginx提供web服务。

1. 修改gitlab的配置文件

禁用自带nginx,$ vim /etc/gitlab/gitlab.rb 在gitlab.rb中修改为以下配置:

#访问域名,域名请换成自己的实际域名
external_url 'http://10.122.60.68:12580'
gitlab_rails['trusted_proxies'] = ['127.0.0.1']

#gitlab 数据存放位置
#git_data_dir "/data/gitlab"
#gitlab 附件上传位置
#gitlab_rails['uploads_directory'] = "/data/gitlab/uploads"

#gitlab 环境协议及访问地址
## 该地址将用在ngx 的 upstream 配置中,很重要,网上示例大多都写成了 server unix:/var/opt/gitlab/gitlab-workhorse/socket fail_timeout=0;实际报ngx 的 502 Bad Gateway 错误
gitlab_workhorse['listen_network'] = "tcp"
gitlab_workhorse['listen_addr'] = "127.0.0.1:8085"

#gitlab 监听地址及端口
unicorn['listen'] = '127.0.0.1'
unicorn['port'] = 8088

#扩展WEB服务(指现有nginx的)的LINUX启动用户,请根据实际环境配置
web_server['external_users'] = ['nobody']

#关闭自带的ngx
nginx['enable'] = false

查看/var/opt/gitlab/gitlab-rails/etc/unicorn.rb/unicorn.rb

#该地址与 gitlab.rb 中的unicorn中的需要一致
listen "127.0.0.1:8088", :tcp_nopush => true
listen "/var/opt/gitlab/gitlab-rails/sockets/gitlab.socket", :backlog => 1024

配置修改完成后,记得一定要生效配置信息 gitlab-ctl reconfigure ,否则无法生效

2. nginx配置

使用单独的nginx配置gitlabserver.conf$ vim NGINX_HOME/gitlabserver.conf

#
upstream gitlab-workhorse {
    #该处与gitlab 中的 gitlab_workhorse 一致
    server 127.0.0.1:8085;
}

server {
    listen 12580;
    #listen [::]:80 ipv6only=on default_server;
    server_name gitlab.68.com;
    server_tokens off; ## Don't show the nginx version number, a security best practice
    #return 301 https://$http_host$request_uri;
    location / {
        #proxy_pass http://gitlab.68.com:12580;
        proxy_pass http://gitlab-workhorse;
    }
    access_log /usr/local/openresty/nginx/logs/gitlab_access.log;
    error_log /usr/local/openresty/nginx/logs/gitlab_error.log;
}

3. 重载

gitlab-ctl reconfigure
gitlab-ctl restart
"$NGINX_HOME"/sbin/nginx -s reload

 

posted @ 2019-12-21 10:32  孙红雷哔哔  阅读(6457)  评论(0编辑  收藏  举报