joephon / blog

极简博客
3 stars 2 forks source link

How to deploy gitlab with nginx and certbot via docker #15

Open joephon opened 4 years ago

joephon commented 4 years ago

Dependencies

OS

Step 1 install docker

sudo apt-get install docker

Step 2 test docker

sudo docker -v
// => Docker version 18.09.2, build 6247962  | or your version

Step 3 pull gitlab image

sudo docker pull gitlab/gitlab-ce:latest

Step 4 run gitlab image

sudo docker run --name='gitlab' -d \
--publish 3443:443 --publish 3080:80 --publish 3022:22 \
--restart always \
--volume /srv/gitlab/config:/etc/gitlab \
--volume /srv/gitlab/logs:/var/log/gitlab \
--volume /srv/gitlab/data:/var/opt/gitlab \
--privileged=true \
gitlab/gitlab-ce:latest

Step 5 test gitlab

sudo docker ps
// =>  (health: starting) | or (healthy)

Step 6 install nginx

sudo apt-get install -y nginx

Step 7 install certbot

sudo apt-get install certbot  python-certbot-nginx

Step 8 config nginx

sudo vim /etc/nginx/sites-enabled/gitlab.conf

// /etc/nginx/sites-enabled/gitlab.conf

server {

  server_name example.com;

  location / {
    # try_files $uri $uri/ =404;
    proxy_redirect off;
    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_pass http://localhost:3080;
    client_max_body_size    100m;
  }

}

Step 9 reload nginx

sudo nginx -s reload

Step 10 register https

sudo certbot --nginx
// =>  Congratulations! Your certificate and chain have been saved

Bingo!

go to visit your self-hosted gitlab server via whatever browser

这篇文价值一块钱