Docker方式部署GitLab,Nginx反向代理Https

一、安裝環(huán)境

  • 操作系統(tǒng):CentOS6.7
  • Web服務(wù):nginx/1.12.0
  • Docker服務(wù):docker/1.7.1

安裝GitLab前請(qǐng)確保以上環(huán)境都已安裝

二、在宿主機(jī)創(chuàng)建數(shù)據(jù)存放目錄

mkdir /srv/gitlab & cd /srv/gitlab
mkdir config logs data

為了方便修改配置和后期維護(hù),需要新建config、logs、data這三個(gè)子欄目來映射到docker里面的gitlab服務(wù)下的目錄

三、拉取gitlab鏡像并啟動(dòng)容器

docker pull gitlab/gitlab-ce:latest
docker run --detach \
 --hostname gitlab.example.cn \
 --publish 20443:443 \
 --publish 20080:80 \
 --publish 20022:22 \
 --name gitlab \
 --restart always\
 --volume /srv/gitlab/config:/etc/gitlab \
 --volume /srv/gitlab/logs:/var/log/gitlab \
 --volume /srv/gitlab/data:/var/opt/gitlab \
 gitlab/gitlab-ce:latest

這里其實(shí)可以不用執(zhí)行docker pull,執(zhí)行docker run的時(shí)候如果沒有對(duì)應(yīng)的image則會(huì)自動(dòng)執(zhí)行pull來獲取image

四、修改gitlab配置文件啟用https支持

cd /srv/gitlab/config
mkdir ssh
cp /data/wwwroot/crtkey/gitlab.crt gitlab.crt
cp /data/wwwroot/crtkey/gitlab.key gitlab.key
vim gitlab.rb

gitlab.crt和gitlab.key是你綁定域名的ssl下發(fā)的秘鑰和證書,需要另外自己申請(qǐng)

開啟gitlab.rb如下配置

external_url 'https://gitlab.example.cn'
nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.key"

保存配置文件,重啟容器

docker restart gitlab

五、配置Nginx反向代理

添加配置信息在nginx對(duì)應(yīng)站點(diǎn)的conf中

## 將HTTP請(qǐng)求全部重定向至HTTPS
server {
    listen       80;
    server_name  gitlab.exmaple.cn;
    charset utf-8;
    access_log  /var/log/nginx/gitlab.access.log;
    error_log  /var/log/nginx/gitlab.error.log;
    rewrite ^ https://gitlab.exmaple.cn;
}

## 請(qǐng)求轉(zhuǎn)發(fā)到GitLab容器
server {
    listen       443 ssl;
    server_name  gitlab.exmaple.cn;
    charset utf-8;
    access_log  /var/log/nginx/gitlab.access.log;
    error_log  /var/log/nginx/gitlab.error.log;
    ssl on;
    ssl_certificate         /data/gitlab/ssl/xiaowo/xiaowo.me.crt;
    ssl_certificate_key     /data/gitlab/ssl/xiaowo/xiaowo.me.key;
    ssl_session_timeout     10m;
    ssl_session_cache       shared:SSL:10m; 
    location / {
        proxy_set_header Host $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 https;
    proxy_pass    https://127.0.0.1:20443;#注意這里的20443端口
    }
}
service nginx restart  #重啟服務(wù)

現(xiàn)在你可以訪問https://gitlab.example.cn,打開了頁面,但奇怪的是頁面樣式亂了,其實(shí)js和css文件都沒有加載到。造成這個(gè)問題的原因是Nginx反向代理的時(shí)候靜態(tài)資源也需要配置代理,下面我們?cè)贜ignx配置文件中添加以下配置:

location ~ .*\.(js|css|png)$ {
    proxy_pass  https://127.0.0.1:20443;
}
service nginx restart  #重啟服務(wù)

OK! 現(xiàn)在你可以愉快的使用https下的gitlab了

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,578評(píng)論 19 139
  • 主要思路: 1. Docker Registry 說明 關(guān)于如何創(chuàng)建和使用本地倉庫,其實(shí)已經(jīng)有很多文章介紹了。因?yàn)?..
    威谷子閱讀 5,840評(píng)論 0 30
  • Docker — 云時(shí)代的程序分發(fā)方式 要說最近一年云計(jì)算業(yè)界有什么大事件?Google Compute Engi...
    ahohoho閱讀 15,850評(píng)論 15 147
  • 以下原文轉(zhuǎn)載于(https://docs.docker.com/docker-for-mac/)(想找中文版的最新...
    Veekend閱讀 7,789評(píng)論 0 17
  • 從今年四月你離開到現(xiàn)在已是十二月了。日子過得真快啊,好像沒了你以后我的心就越發(fā)的平靜了。就像那深深的湖面,石子掉落...
    qingle閱讀 200評(píng)論 0 0

友情鏈接更多精彩內(nèi)容