Ubuntu 16.04 gitlab 설치 nginx 연동

블로그 운영중인 서버에 gitlab을 설치하기로 했다. gitlab은 잘 사용하진 않으면서 틈만나면 설치해보는 것 같다. 고통스러운 것은 그렇게 매번 설치할 때마다 제대로 안 되서 한번씩 삽질을 하게 된다는 것이다.

기본적인 설치 방법은 gitlab 공식 홈페이지에 있는 내용을 따랐다. ubuntu 16.04 64bit 환경에서는 특별한 의존 패키지를 복잡하게 설치할 필요없이 인스톨이 가능하다.

$ sudo apt-get update
$ sudo apt-get install -y curl openssh-server ca-certificates
$ sudo apt-get install -y postfix   # 메일 관련 패키지인데 skip 해도 된다.

repository 등록

$ curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bas

gitlab 설치

$ sudo EXTERNAL_URL="http://gitlab.example.com" apt-get install gitlab-ee

위에서 “http://gitlab.example.com”은 외부에서 접속할 주소이므로 본인 환경에 맞게 설정한다.

nginx 설정

gitlab을 패키지 인스톨하게 되면 기본적으로 gitlab에 포함된 내장 nginx를 사용한다. 만약 서버에 apache나 nginx를 이미 동작하고 있다면 충돌이 나서 gitlab이 정상적으로 구동되지 않을 수 있다. 필자의 경우 다음과 같이 포트 설정을 변경하고 configuration 파일을 등록해주었다.

port 변경

$ sudo vi /etc/gitlab/gitlab.rb

위 파일을 열고 다음을 추가해준다.

nginx['enable'] = false
unicorn['port'] = 8180
unicorn['listen'] = 'localhost'

port는 본인이 원하는 것으로 설정해준다.

gitlab 관련 프로세스를 재시작해준다.

$ sudo gitlab-ctl reconfigure
$ sudo gitlab-ctl restart

gitlab.rb설정과 nginx 설정이 제대로 안 되는 경우 gitlab 페이지를 열었을 때 css나 js 가 제대로 호출이 안되 페이지가 깨지거나 502 에러가 발생하는 경우가 있으니 설정이 제대로 되었나 확인이 필요하다. 또한, 테스트로 사용하는 브라우저가 캐싱을 했거나 설정이 반영되는데 시간이 걸릴 수도 있으니 주의하기 바란다.

nginx config 추가

링크 페이지에 들어가면 config 파일 레시피를 다운로드할 수 있다. 해당 파일을 다음과 같이 수정했다.

$ vi /etc/nginx/sites-available/gitlab.conf

gitlab.conf

## 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;
  listen [::]:80;
  server_name gitlab.example.com; ## 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;
  }
}

위 설정 파일에서 gitlab.example.com을 본인이 external uri로 설정했던 것으로 변경해준다.

nginx restart

$ sudo /etc/init.d/nginx restart

참고

This Post Has One Comment

  1. riley

    감사합니다! ! ㅎㅎ 많은 도움이 되었습니다~

Leave a Reply