Centos安装配置gitlab

一、安装HTTP和SSH、postfix服务

1、命令如下

sudo yum install curl openssh-server openssh-clients postfix cronie -y
sudo service postfix start
sudo chkconfig postfix on
sudo lokkit -s http -s ssh

二、下载gitlab安装文件和安装gitlab

1、系统默认下载

curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo yum install gitlab-ce -y

2、指定版本下载

选择版本连接,源文件下载渠道1 (https://packages.gitlab.com/gitlab/gitlab-ce) 和 源文件下载渠道2 (https://about.gitlab.com/downloads/archives/)

curl -LJO https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/6/gitlab-ce-XXX.rpm/download
rpm -i gitlab-ce-XXX.rpm

我下载版本7.5.3

wget https://downloads-packages.s3.amazonaws.com/centos-6.6/gitlab-7.5.3_omnibus.5.2.1.ci-1.el6.x86_64.rpm
sudo rpm -i gitlab-7.5.3_omnibus.5.2.1.ci-1.el6.x86_64.rpm

三、启动gitlab

命令如下:

//启动、并且查看配置
sudo gitlab-ctl reconfigure
//查看状态
sudo gitlab-ctl status
//启动Gitlab所有组件
sudo gitlab-ctl start
//停止Gitlab所有组件
sudo gitlab-ctl stop
//重启Gitlab所有组件
sudo gitlab-ctl restart

可能会出现ChildConvergeError异常 (http://yanmin99.com/test)

四、访问服务器

1、默认用户名和密码

username:root
password:5iveL!fe

2、访问gitlab

地址http:ip,gitlab默认nginx是80端口

  • 登陆页面

未分类

  • 修改密码

未分类

  • 主页面

未分类

配置jenkins实现gitlab自动化构建

构建

需要将jenkins服务器上 jenkins用户的公钥发送给 目标服务器的gs用户,使得在jenkins上能用gs免密登录目标服务器

复制密钥到目标机器上(需要登录到的机器)

ssh-copy-id -i  .ssh/id_rsa.pub [email protected](目标机器)

未分类

自动化构建

需要配置gitlab的钩子 ,并在jenkins上做配置

未分类

未分类

点击Test Hook,测试配置,如果返回Hook successfully executed.表示配置成功,只要下次push代码就可以自动发布,Jenkins效果如下图

未分类

自动构建后,邮件通知。

使用Docker或者docker-compose搭建gitlab

一. 直接下载docker-ce

1. 拉取gitlab/gitlab-ce

Randy:~ Randy$ docker pull gitlab/gitlab-ce
Using default tag: latest

2. 运行gitlab/gitlab-ce

Randy:~ Randy$ docker run -d --publish 8443:443 --publish 8001:80 --publish 8022:22 --name gitlab-randy --restart always gitlab/gitlab-ce

其中使用publish参数映射host主机上的8443到docker-ce上面的443端口,并制定使用bash。此处可以使用–volume参数来指定docker-ce中的文件到host主机上的路径以便于升级,此处仅作为测试使用。

3. 验证http://127.0.0.1:8001/可以登录,首次登录需要修改密码

二. 使用Docker-compose方式

这种方式是比较灵活,也是官方推荐的安装方式。实际上就是把启动docker的参数配置到文件中,并通过docker-compose up调用。步骤如下:

1. 下载docker-compose.yml文件

wget https://raw.githubusercontent.com/sameersbn/docker-gitlab/master/docker-compose.yml
[root@randysun ~]# wget https://raw.githubusercontent.com/sameersbn/docker-gitlab/master/docker-compose.yml
--2017-08-06 11:36:43--  https://raw.githubusercontent.com/sameersbn/docker-gitlab/master/docker-compose.yml
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.72.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.72.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3836 (3.7K) [text/plain]
Saving to: ‘docker-compose.yml’

100%[============================================================================>] 3,836       --.-K/s   in 0s      

2017-08-06 11:36:44 (64.7 MB/s) - ‘docker-compose.yml’ saved [3836/3836]

2. 在第一步中下载好的文件路径下运行docker-compose up

[root@randysun ~]# docker-compose up
Creating network "root_default" with the default driver
Pulling postgresql (sameersbn/postgresql:9.6-2)...
9.6-2: Pulling from sameersbn/postgresql
c60055a51d74: Downloading [=>                                                 ]  1.615MB/65.69MB
755da0cdb7d2: Download complete
969d017f67e6: Download complete
37c9a9113595: Download complete
a3d9f8479786: Download complete
e43d9de53575: Downloading [==================>                                ]  1.754MB/4.702MB
cddf24084b61: Download complete
f23b95c5f17c: Waiting
3965edbc705f: Waiting
4e6c393fb7f5: Waiting

3. 验证

配置GitLab触发jenkins自动构建项目

目的为在公司的测试环境当中一旦开发向gitlab仓库提交成功代码,gitlab通知jenkins进行构建项目、代码质量测试然后部署至测试环境,注意这只是测试环境,而生产环境依然需要手动部署代码。

1、jenkins配置

1.1 安装Gitlab Hook Plugin插件

系统管理-管理插件-可选插件-Gitlab Hook Plugin和Build Authorization Token Root Plugin

未分类

1.2 生成随机token

# openssl rand -hex 12

0f2a47c861133916d2e299e3

1.3 创建项目触发器

项目-配置-构建触发器:

http://192.168.3.199:8080/jenkins/project/web-demo

未分类

2、配置gitlab

2.1 在Git项目配置界面设置链接和token

登录gitlab,在这个项目下找到钩子配置的地方

未分类

选择项目-设置-webhooks:

插件使用介绍,https://wiki.jenkins-ci.org/display/JENKINS/Build+Token+Root+Plugin

http://192.168.3.199:8080/jenkins/buildByToken/build?job=web-demo&token=0f2a47c861133916d2e299e3

http://jenkins服务器地址:8080/buildByToken/build?job=项目名&token=token值

未分类

2.2 测试

未分类

报错:

hook executed successfully but returned http 404

本次是因为没有在项目后面加上jenkins这个路径

2.3 测试,看到显示201表示成功

3、向git服务器提交代码,验证是否可以自动部署

3.1 提交代码

[www@master code]$ git clone [email protected]:web/web-demo.git
[www@master web-demo]$ echo "Build token root plugin" > index.html 
[www@master web-demo]$ git add 'index.html'
[www@master web-demo]$ git commit -m 'build token root plugin test'
[master beb37cb] build token root plugin test
1 file changed, 1 insertion(+), 1 deletion(-)
[www@master web-demo]$ git push origin master
Counting objects: 5, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 281 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To [email protected]:web/web-demo.git
c02523b..beb37cb master -> master

3.2 jenkins服务器的日志记录

[root@node1 tomcat]# tail -f /usr/local/tomcat/logs/catalina.out

未分类

3.3 jenkins项目构建

未分类

未分类

3.4 访问web界面验证代码是否最新的

未分类

3.5 jenkins控制台输出信息

未分类

gitlab数据的备份及恢复方法

Gitlab 创建备份

使用Gitlab一键安装包安装Gitlab非常简单, 同样的备份恢复与迁移也非常简单. 使用一条命令即可创建完整的Gitlab备份:

gitlab-rake gitlab:backup:create

使用以上命令会在/var/opt/gitlab/backups目录下创建一个名称类似为1393513186_gitlab_backup.tar的压缩包, 这个压缩包就是Gitlab整个的完整部分, 其中开头的1393513186是备份创建的日期.

Gitlab 修改备份文件默认目录

你也可以通过修改/etc/gitlab/gitlab.rb来修改默认存放备份文件的目录:

gitlab_rails['backup_path'] = '/mnt/backups'

/mnt/backups修改为你想存放备份的目录即可, 修改完成之后使用gitlab-ctl reconfigure命令重载配置文件即可.

Gitlab 自动备份

也可以通过crontab使用备份命令实现自动备份:

sudo su -
crontab -e

加入以下, 实现每天凌晨2点进行一次自动备份:

0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create

Gitlab 恢复

同样, Gitlab的从备份恢复也非常简单:

# 停止相关数据连接服务
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq

# 从1393513186编号备份中恢复
gitlab-rake gitlab:backup:restore BACKUP=1393513186

# 启动Gitlab
sudo gitlab-ctl start

Gitlab迁移

迁移如同备份与恢复的步骤一样, 只需要将老服务器/var/opt/gitlab/backups目录下的备份文件拷贝到新服务器上的/var/opt/gitlab/backups即可(如果你没修改过默认备份目录的话). 但是需要注意的是新服务器上的Gitlab的版本必须与创建备份时的Gitlab版本号相同. 比如新服务器安装的是最新的7.60版本的Gitlab, 那么迁移之前, 最好将老服务器的Gitlab 升级为7.60在进行备份.

其他

最新版本的Gitlab已经修复了HTTPS设备的BUG, 现在使用官方HTTPS配置即可轻松启用HTTPS.

配置gitlab通过smtp发送邮件

1. 编辑/etc/gitlab/gitlab.rb文件(加到文件最后面就好了)。以QQ企业邮箱为例:

gitlab_rails['smtp_enable'] = true

gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"

gitlab_rails['smtp_port'] = 465

gitlab_rails['smtp_user_name'] = "[email protected]"

gitlab_rails['smtp_password'] = "******"

gitlab_rails['smtp_authentication'] = "login"

gitlab_rails['smtp_enable_starttls_auto'] = true

gitlab_rails['smtp_tls'] = true

gitlab_rails['gitlab_email_from'] = '[email protected]'

有的教程可能会说去改/opt/gitlab/etc/gitlab.rb,是错的,一切以官网文档为准

2. 重新配置gitlab

gitlab-ctl reconfigure

3. 通过命令行测试邮件是否发送成功(也可以不测)

gitlab-rails console

irb(main):003:0> Notify.test_email('[email protected]', 'Message Subject', 'Message Body').deliver_now

Centos7系统安装配置GitLab服务器

1、首先

sudo yum update 

更新当前库

2、执行以下命令

sudo yum install curl policycoreutils openssh-server openssh-clients -y 
sudo systemctl enable sshd 
sudo systemctl start sshd 
sudo yum install postfix  
sudo systemctl enable postfix 
sudo systemctl start postfix 
sudo firewall-cmd --permanent --add-service=http 
sudo systemctl reload firewalld 

其中 sudo yum install postfix 可能会报错,部分环境可能已经配置好此步,报错直接跳过。

3、添加gitlb官方地址至源文件

curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash 

提示如下:

The repository is setup! You can now install packages.

即可以开始安装

执行安装:

sudo yum install gitlab-ce -y 

提示如下:

Installed:
  gitlab-ce.x86_64 0:9.4.2-ce.0.el7                                             

Complete!

即安装成功

4、执行配置脚本

sudo gitlab-ctl reconfigure

此步骤大概会执行3分钟左右,结果大概如下:

unning handlers:
Running handlers complete
Chef Client finished, 362/517 resources updated in 03 minutes 40 seconds
gitlab Reconfigured!

即可通过访问服务器地址访问,并进行初始化配置(默认为80端口,配置文件为:/etc/gitlab/gitlab.rb)

docker安装部署gitlab 配置使用部外nginx

一、docker安装gitlab镜像

1,镜像信息

https://hub.docker.com/r/gitlab/gitlab-ce/

docker pull gitlab/gitlab-ce

2,启动镜像

sudo docker run --detach 
 --hostname git.tmy.com 
 --publish 8929:80 --publish 2289:22 
 --name gitlab 
 --restart always 
 --volume /data/gitlab/config:/etc/gitlab 
 --volume /data/gitlab/logs:/var/log/gitlab 
 --volume /data/gitlab/data:/var/opt/gitlab 
 gitlab/gitlab-ce:latest

文档地址:https://docs.gitlab.com/omnibus/docker/#run-the-image

3,访问本机安装的gitlab

127.0.0.1:8929 端口号为步骤2中设置的端口号。

此处不知何种原因,启动了需要等待几分钟才可以访问,知道的大神可以六个言交流下。

可以访问之后继续往下走。

二、配置使用外部的nginx服务器

1,关闭gitlab内部的nginx服务

官方文档地址:https://docs.gitlab.com/omnibus/settings/nginx.html#using-a-non-bundled-web-server

启动的时候映射出来的目录
vim /data/gitlab/config/gitlab.rb 

在配置文件最末尾加上配置
nginx['enable'] = false 
web_server['external_users'] = ['www-data']

使配置生效
docker exec gitlab gitlab-ctl reconfigure

2,配置本机上的nginx

新nginx虚拟机配置文件,我的虚拟机配置文件在/usr/local/nginx/conf/vhost

vim /usr/local/nginx/conf/vhost/git.tmy.com.conf

下载官方的配置文件

https://gitlab.com/gitlab-org/gitlab-recipes/tree/master/web-server/nginx

配置文件有http 和 https两个版本,这里我选择了http第一个

## GitLab 8.3+
##
## Lines starting with two hashes (##) are comments with information.
## Lines starting with one hash (#) are configuration parameters that can be uncommented.
##
##################################
## CONTRIBUTING ##
##################################
##
## If you change this file in a Merge Request, please also create
## a Merge Request on https://gitlab.com/gitlab-org/omnibus-gitlab/merge_requests
##
###################################
## configuration ##
###################################
##
## See installation.md#using-https for additional HTTPS configuration details.

upstream gitlab-workhorse {
 server unix:/var/opt/gitlab/gitlab-workhorse/socket;
}

## Normal HTTP host
server {
 ## Either remove "default_server" from the listen line below,
 ## or delete the /etc/nginx/sites-enabled/default file. This will cause gitlab
 ## to be served if you visit any address that your server responds to, eg.
 ## the ip address of the server (http://x.x.x.x/)n 0.0.0.0:80 default_server;
 listen 0.0.0.0:80 default_server;
 listen [::]:80 default_server;
 server_name YOUR_SERVER_FQDN; ## Replace this with something like gitlab.example.com
 server_tokens off; ## Don't show the nginx version number, a security best practice
 root /opt/gitlab/embedded/service/gitlab-rails/public;

 ## See app/controllers/application_controller.rb for headers set

 ## Individual nginx logs for this GitLab vhost
 access_log /var/log/nginx/gitlab_access.log;
 error_log /var/log/nginx/gitlab_error.log;

 location / {
 client_max_body_size 0;
 gzip off;

 ## https://github.com/gitlabhq/gitlabhq/issues/694
 ## Some requests take more than 30 seconds.
 proxy_read_timeout 300;
 proxy_connect_timeout 300;
 proxy_redirect off;

 proxy_http_version 1.1;

 proxy_set_header Host $http_host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header X-Forwarded-Proto $scheme;

 proxy_pass http://gitlab-workhorse;
 }
}

将配置文件写入刚才创建的虚拟机文件配置文件中。修改

#找到
upstream gitlab-workhorse {
 server unix:/var/opt/gitlab/gitlab-workhorse/socket;
}
#修改为
upstream gitlab-workhorse {
 server unix:/data/gitlab/data/gitlab-workhorse/socket;
}
#找到
server_name YOUR_SERVER_FQDN;
#修改为
server_name git.tmy.com 【域名是你自己配置好的域名】
#找到
access_log /var/log/nginx/gitlab_access.log;
error_log /var/log/nginx/gitlab_error.log;
#改为
access_log /data/wwwlogs/gitlab_access.log;
error_log/data/wwwlogs/gitlab_error.log;
#上边是日志文件而已,改称你自己的就行

配置完成后检查nginx -t 是否正常,没问题重新载入配置即可。

三、修改目录权限

chown -R www:www /data/gitlab/data/gitlab-workhorse/

修改完成后访问git.tmy.com 即可进入gitlab的web界面了

CentOS 6 GitLab的安装配置与使用方法

前言

  • GitLab是利用 Ruby on Rails 一个开源的版本管理系统,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目。
  • 它拥有与Github类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。
  • 团队成员可以利用内置的简单聊天程序(Wall)进行交流。
  • 它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找。

Git的家族成员

  • Git:是一种版本控制系统,是一个命令,是一种工具。
  • Gitlib:是用于实现Git功能的开发库。
  • Github:是一个基于Git实现的在线代码托管仓库,包含一个网站界面,向互联网开放。
  • GitLab:是一个基于Git实现的在线代码仓库托管软件,你可以用gitlab自己搭建一个类似于Github一样的系统,一般用于在企业、学校等内部网络搭建git私服。

Gitlab的服务构成

  • Nginx:静态web服务器。
  • gitlab-shell:用于处理Git命令和修改authorized keys列表。
  • gitlab-workhorse:轻量级的反向代理服务器。
  • logrotate:日志文件管理工具。
  • postgresql:数据库。
  • redis:缓存数据库。
  • sidekiq:用于在后台执行队列任务(异步执行)。
  • unicorn:An HTTP server for Rack applications,GitLab Rails应用是托管在这个服务器上面的。

GitLab工作流程

未分类

GitLab Shell

  • GitLab Shell有两个作用:为GitLab处理Git命令、修改authorized keys列表。
  • 当通过SSH访问GitLab Server时,GitLab Shell会:
  • 限制执行预定义好的Git命令(git push, git pull, git annex)
  • 调用GitLab Rails API 检查权限
  • 执行pre-receive钩子(在GitLab企业版中叫做Git钩子)
  • 执行你请求的动作 处理GitLab的post-receive动作
  • 处理自定义的post-receive动作
  • 当通过http(s)访问GitLab Server时,工作流程取决于你是从Git仓库拉取(pull)代码还是向git仓库推送(push)代码。
  • 如果你是从Git仓库拉取(pull)代码,GitLab Rails应用会全权负责处理用户鉴权和执行Git命令的工作;
  • 如果你是向Git仓库推送(push)代码,GitLab Rails应用既不会进行用户鉴权也不会执行Git命令,它会把以下工作交由GitLab Shell进行处理:
  1. 调用GitLab Rails API 检查权限
  2. 执行pre-receive钩子(在GitLab企业版中叫做Git钩子)
  3. 执行你请求的动作
  4. 处理GitLab的post-receive动作
  5. 处理自定义的post-receive动作

GitLab Workhorse

GitLab Workhorse是一个敏捷的反向代理。它会处理一些大的HTTP请求,比如文件上传、文件下载、Git push/pull和Git包下载。其它请求会反向代理到GitLab Rails应用,即反向代理给后端的unicorn。

Gitlab环境部署

ECS配置要求:内存2G以上

方法一:镜像部署

镜像名称:GitLab代码管理(Centos 64位 | GitLab) | 镜像帮助文档

进入镜像详情页面,单击立即购买,按提示步骤购买 ECS 实例。

购买完成之后,登录”ECS 管理控制台”,在左边导航栏里,单击”实例”,进入 ECS 实例列表页,选择所购 ECS 实例所在的地域,并找到所购 ECS 实例,在”IP 地址”列获取该实例的公网 IP 地址。

注意:镜像部署好后默认是禁止远端访问的,所以直接访问ECS服务器的公网IP是不能访问到GitLab的登录界面的,请先运行/alidata目录下的gitlab_opennet.sh脚本,开启远程访问,然后再通过浏览器访问公网IP来访问GitLab的主页。

方法二:手动部署:

1、配置yum源

vim /etc/yum.repos.d/gitlab-ce.repo

复制以下内容:

[gitlab-ce]
name=gitlab-ce
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6
Repo_gpgcheck=0
Enabled=1
Gpgkey=https://packages.gitlab.com/gpg.key

未分类

2、更新本地yum缓存

sudo yum makecache

未分类

3、安装GitLab社区版

sudo yum intall gitlab-ce        #自动安装最新版
sudo yum install gitlab-ce-x.x.x    #安装指定版本

未分类

GitLab常用命令:

sudo gitlab-ctl start    # 启动所有 gitlab 组件;
sudo gitlab-ctl stop        # 停止所有 gitlab 组件;
sudo gitlab-ctl restart        # 重启所有 gitlab 组件;
sudo gitlab-ctl status        # 查看服务状态;
sudo gitlab-ctl reconfigure        # 启动服务;
sudo vim /etc/gitlab/gitlab.rb        # 修改默认的配置文件;
gitlab-rake gitlab:check SANITIZE=true --trace    # 检查gitlab;
sudo gitlab-ctl tail        # 查看日志;

GitLab使用

登录GitLab

1、在浏览器的地址栏中输入ECS服务器的公网IP即可登录GitLab的界面,第一次登录使用的用户名和密码为 root 和 5iveL!fe。

未分类

2、首次登录会强制用户修改密码。密码修改成功后,输入新密码进行登录。

未分类

未分类

创建Project

1、安装Git工具linux:安装Git,使用自带的源安装。

yum install git

未分类

2、生成密钥文件

使用ssh-keygen生成密钥文件.ssh/id_rsa.pub。

未分类

未分类

3.在GitLab的主页中新建一个Project

未分类

未分类

4.添加ssh key导入步骤2中生成的密钥文件内容:

未分类

未分类

ssh key添加完成:

未分类

项目地址,该地址在进行clone操作时需要用到:

未分类

简单配置

1、配置使用Git仓库的人员姓名

git config --global user.name "上海驻云"    

2、配置使用Git仓库的人员email,填写自己的公司邮箱

git config --global user.email "[email protected]" 

3、克隆项目,在本地生成同名目录,并且目录中会有所有的项目文件

git clone git@iZbp1h7fx16gkr9u4gk8v3Z:root/test.git

未分类

上传文件

1、进入到项目目录

cd test/ 

2、创建需要上传到GitLab中的目标文件

echo “test” >  /root/test.sh

3、将目标文件或者目录拷贝到项目目录下

cp /root/test.sh ./    

未分类

4、将test.sh文件加入到索引中

git add test.sh 

5、将test.sh提交到本地仓库

git commit -m “test.sh”

6、将文件同步到GitLab服务器上

git push -u origin master 

未分类

7、在网页中查看上传的test.sh文件已经同步到GitLab中

未分类

centos7安装配置gitlab(使用外部nginx)

1、安装依赖:

sudo yum install curl policycoreutils openssh-server openssh-clients
sudo systemctl enable sshd
sudo systemctl start sshd
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
sudo firewall-cmd --permanent --add-service=http
sudo systemctl reload firewalld

2、添加gitlab源:

curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash

3、安装gitlab-ce

sudo yum install gitlab-ce

如果您不喜欢通过管道脚本安装存储库,您可以在这里找到整个脚本并手动选择并下载包并使用:

curl -LJO https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-XXX.rpm/download
rpm -i gitlab-ce-XXX.rpm

4、配置gitlab:

sudo gitlab-ctl reconfigure
至此gitlab安装成功,默认用户名为root。

5、停止gitlab自带的nginx

打开文件$sudo vi /etc/gitlab/gitlab.rb。
将nginx['enable'] = ture改为nginx['enable'] = false
重启gitlab:sudo gitlab-ctl reconfigure。

6、修改gitlab域名:

打开/etc/gitlab/gitlab.rb文件,将external_url参数修改为自己的域名。

7、添加外部nginx的gitlab配置文件:

vim /etc/nginx/conf.d/gitlab.conf

添加以下内容:

upstream gitlab {
# 7.x 版本在此位置
# server unix:/var/opt/gitlab/gitlab-rails/tmp/sockets/gitlab.socket;
# 8.0 位置
server unix://var/opt/gitlab/gitlab-rails/sockets/gitlab.socket;
}

server {
 listen *:80;

 server_name gitlab.xuwanqiu.com; # 请修改为你的域名

 server_tokens off; # don't show the version number, a security best practice
 root /opt/gitlab/embedded/service/gitlab-rails/public;

 # Increase this if you want to upload large attachments
 # Or if you want to accept large git objects over http
 client_max_body_size 250m;

 # individual nginx logs for this gitlab vhost
 access_log /var/log/gitlab/nginx/gitlab_access.log;
 error_log /var/log/gitlab/nginx/gitlab_error.log;

 location / {
 # serve static files from defined root folder;.
 # @gitlab is a named location for the upstream fallback, see below
 try_files $uri $uri/index.html $uri.html @gitlab;
 }

 # if a file, which is not found in the root folder is requested,
 # then the proxy pass the request to the upsteam (gitlab unicorn)
 location @gitlab {
 # If you use https make sure you disable gzip compression
 # to be safe against BREACH attack

 proxy_read_timeout 300; # Some requests take more than 30 seconds.
 proxy_connect_timeout 300; # Some requests take more than 30 seconds.
 proxy_redirect off;

 proxy_set_header X-Forwarded-Proto $scheme;
 proxy_set_header Host $http_host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header X-Frame-Options SAMEORIGIN;

 proxy_pass http://gitlab;
 }

 # Enable gzip compression as per rails guide: http://guides.rubyonrails.org/asset_pipeline.html#gzip-compression
 # WARNING: If you are using relative urls do remove the block below
 # See config/application.rb under "Relative url support" for the list of
 # other files that need to be changed for relative url support
 location ~ ^/(assets)/ {
 root /opt/gitlab/embedded/service/gitlab-rails/public;
 # gzip_static on; # to serve pre-gzipped version
 expires max;
 add_header Cache-Control public;
 }

 error_page 502 /502.html;
}

参考资料:

http://blog.csdn.net/peterxiaoq/article/details/73330302
http://www.cnblogs.com/lixiuran/p/6761299.html
https://segmentfault.com/q/1010000003695935?_ea=337139
https://laravel-china.org/topics/2829/centos-7-install-gitlab-ce-community-edition-and-modify-the-default-nginx
https://about.gitlab.com/installation/#centos-7
https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md
http://jiankg.github.io/2015/06/12/%E5%9C%A8centos7%E4%B8%8A%E6%90%AD%E5%BB%BAgitlab%E7%9A%84%E6%AD%A3%E7%A1%AE%E5%A7%BF%E5%8A%BF/