# 添加包的key curl https://packages.gitlab.com/gpg.key 2> /dev/null | sudo apt-key add - &>/dev/null # 写入 sudo sh -c 'echo deb https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu xenial main > /etc/apt/sources.list.d/gitlab-ce.list' # 更新 sudo apt update
sudo apt install gitlab-ce
3 修改 gitlab 配置
1 2 3 4 5 6 7 8 9 10 11 12
sudo vi /etc/gitlab/gitlab.rb # 修改 external_url 'https://gitlab.example.com' ## My Conf # close nginx nginx['enable'] = false # Set the internal API URL gitlab_rails['internal_api_url'] = 'https://gitlab.example.com' # Define the web server process user (ubuntu/nginx) web_server['external_users'] = ['www-data']
cd /etc/nginx/sites-available sudo vi gitlab.example.com.conf # 写入 upstream gitlab-workhorse { server unix://var/opt/gitlab/gitlab-workhorse/socket fail_timeout=0; }
access_log /var/log/gitlab/nginx/gitlab_access.log; error_log /var/log/gitlab/nginx/gitlab_error.log; # Ensure Passenger uses the bundled Ruby version passenger_ruby /opt/gitlab/embedded/bin/ruby; # Correct the $PATH variable to included packaged executables passenger_env_var PATH "/opt/gitlab/bin:/opt/gitlab/embedded/bin:/usr/local/bin:/usr/bin:/bin"; # Make sure Passenger runs as the correct user and group to # prevent permission issues passenger_user git; passenger_group git; # Enable Passenger & keep at least one instance running at all times passenger_enabled on; passenger_min_instances 1;
location ~ ^/[\w\.-]+/[\w\.-]+/(info/refs|git-upload-pack|git-receive-pack)$ { # 'Error' 418 is a hack to re-use the @gitlab-workhorse block error_page 418 = @gitlab-workhorse; return 418; }
location ~ ^/[\w\.-]+/[\w\.-]+/repository/archive { # 'Error' 418 is a hack to re-use the @gitlab-workhorse block error_page 418 = @gitlab-workhorse; return 418; }
location ~ ^/api/v3/projects/.*/repository/archive { # 'Error' 418 is a hack to re-use the @gitlab-workhorse block error_page 418 = @gitlab-workhorse; return 418; } # Build artifacts should be submitted to this location location ~ ^/[\w\.-]+/[\w\.-]+/builds/download { client_max_body_size 0; # 'Error' 418 is a hack to re-use the @gitlab-workhorse block error_page 418 = @gitlab-workhorse; return 418; } # Build artifacts should be submitted to this location location ~ /ci/api/v1/builds/[0-9]+/artifacts { client_max_body_size 0; # 'Error' 418 is a hack to re-use the @gitlab-workhorse block error_page 418 = @gitlab-workhorse; return 418; } # Build artifacts should be submitted to this location location ~ /api/v4/jobs/[0-9]+/artifacts { client_max_body_size 0; # 'Error' 418 is a hack to re-use the @gitlab-workhorse block error_page 418 = @gitlab-workhorse; return 418; }
# For protocol upgrades from HTTP/1.0 to HTTP/1.1 we need to provide Host header if its missing if ($http_host = "") { # use one of values defined in server_name set $http_host_with_default "gitlab.example.com"; }
if ($http_host != "") { set $http_host_with_default $http_host; }
location @gitlab-workhorse {
## https://github.com/gitlabhq/gitlabhq/issues/694 ## Some requests take more than 30 seconds. proxy_read_timeout 3600; proxy_connect_timeout 300; proxy_redirect off;
# Do not buffer Git HTTP responses proxy_buffering off;
## The following settings only work with NGINX 1.7.11 or newer # ## Pass chunked request bodies to gitlab-workhorse as-is # proxy_request_buffering off; # proxy_http_version 1.1; } ## Enable gzip compression as per rails guide: ## http://guides.rubyonrails.org/asset_pipeline.html#gzip-compression ## WARNING: If you are using relative urls 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; }