阿里云ubuntu服务器在本地nginx的基础上安装gitlab

准备在阿里云服务器上安装gitlab,以前在本地安装过,过程并不复杂,只是在换源上花了点时间,但万万没想到,用了云服务器后,由于安装了nginx用来配置本身的项目,结果形成了gitlab内置的nginx和本地冲突,花了3天时间才处理好这问题。这里就记录一下配置过程,以避免下次遇到。html

处理两个nginx冲突的方法仍是挺多的

1. 禁用gitlab自带nginx,在本地增长gitlab的配置
2. 禁用本地nginx,用gitlab的(这个我没有尝试,但网上有此种操做的文章)
3. 两个nginx并用,只要解决端口冲突就好

以上方法,我尝试了一、3,都成功了。但方法三两个nginx并行总感受不靠谱,因而我最终选择了方法一,如下是详情

一、下载好gitlab后进行配置nginx

编辑配置文件git

#vi /etc/gitlab/gitlab.rb

修改访问路径(http://localhost:1024 是我改的 这里你要改为本身的端口)程序员

external_url 'http://localhost:1024'

使配置生效(这里说明如下为何配置没改完就先操做此命令,由于配置不生效,不少文件不生成,以后的不少操做作不了)web

#sudo gitlab-ctl reconfigure

在配置文件中关闭gitlab nginx (要么直接复制,要么找到位置去掉注释修改)ruby

nginx['enable'] = false

容许启动gitlab的用户(这里用户名从本地nginx里找) 服务器

web_server['external_users'] = ['nobody']

配置nginx (添加到原nginx配置中)app

#vi /usr/local/nginx/conf/nginx.conf


upstream gitlab {
  # 7.x 版本在此位置
  # server unix:/var/opt/gitlab/gitlab-rails/tmp/sockets/gitlab.socket;
  # 8.0 位置
  server unix://var/opt/gitlab/gitlab-rails/sockets/gitlab.socket;
}

server {
  listen *:1024;

  server_name 孙宇豪.online;   # 请修改成你的域名

  server_tokens off;     # don't show the version number, a security best practice
  root /opt/gitlab/embedded/service/gitlab-rails/public;

  # Increase this if you want to upload large attachments
  # Or if you want to accept large git objects over http
  client_max_body_size 250m;

  # individual nginx logs for this gitlab vhost
  access_log  /var/log/gitlab/nginx/gitlab_access.log;
  error_log   /var/log/gitlab/nginx/gitlab_error.log;

  location / {
	# serve static files from defined root folder;.
	# [@gitlab](https://my.oschina.net/daodaoclub) is a named location for the upstream fallback, see below
	try_files $uri $uri/index.html $uri.html [@gitlab](https://my.oschina.net/daodaoclub);
  }

  # if a file, which is not found in the root folder is requested,
  # then the proxy pass the request to the upsteam (gitlab unicorn)
  location [@gitlab](https://my.oschina.net/daodaoclub) {
	# If you use https make sure you disable gzip compression 
	# to be safe against BREACH attack

	proxy_read_timeout 300; # Some requests take more than 30 seconds.
	proxy_connect_timeout 300; # Some requests take more than 30 seconds.
	proxy_redirect     off;

	proxy_set_header   X-Forwarded-Proto $scheme;
	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-Frame-Options   SAMEORIGIN;

	proxy_pass http://gitlab;
  }

  # Enable gzip compression as per rails guide: http://guides.rubyonrails.org/asset_pipeline.html#gzip-compression
  # WARNING: If you are using relative urls do 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;
  }

  error_page 502 /502.html;
}

我还改了一下 unicorn.rb 文件的监听接口,由于它占用了个人8080接口socket

#vi /var/opt/gitlab/gitlab-rails/etc/unicorn.rb

重启nginxtcp

#sudo /usr/local/nginx/sbin/nginx -s reload

重启gitlab

#sudo gitlab-ctl reconfigure

用你的ip+端口号访问gitlab

通常到这里就成功了,固然还有可能碰到一些问题,好比端口冲突等,在出现问题后必须先去日志看状况,不能一味的只经过问题搜答案,毕竟形成问题的缘由不少,仅仅只靠搜出来的结果不停的尝试,常常会形成更多的问题,最后有可能把整个环境都整崩了

查看gitlab日志

#sudo gitlab-ctl tail

我遇到过端口冲突的情况,因而用命令

#sudo fuser -k 1024/tcp

没权限形成的访问页面502

#sudo chmod -R o+x /var/opt/gitlab/gitlab-rails
#chmod 755 /var/opt/gitlab/gitlab-rails/sockets

出现了问题别着急,耐心细心坚持下去总能解决,良好的解决问题的能力是一个优秀程序员必备的的素养

Nothing is impossible
相关文章
相关标签/搜索