牛下载:绿色软件官方软件免费下载基地!
所在位置:首页 > 新闻资讯 > docker安装部署gitlab 配置使用部外nginx

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

发布时间:2020-04-14 17:50:04来源:阅读:

一、docker安装gitlab镜像

1,镜像信息

http://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

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

3,访问本机安装的gitlab

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

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

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

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

1,关闭gitlab内部的nginx服务

官方文档地址:http://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

下载官方的配置文件

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

配置文件有http 和 http两个版本,这里我选择了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 http://gitlab.com/gitlab-org/omnibus-gitlab/merge_requests
##
###################################
## configuration ##
###################################
##
## See installation.md#using-http 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;

 ## http://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界面了

反对
收藏
  • 热门资讯
  • 最新资讯
  • 应用排行榜
  • 游戏排行榜