Centos7.5 安装gitlab配置nginx(禁用自带的,用已经安装的nginx)

一、安装gitlab

安装可参考:https://blog.whsir.com/post-3081.html
https://blog.csdn.net/qq_32786873/article/details/80975880

二、修改gitlab配置文件

1、禁用自带nginx
vim /etc/gitlab/gitlab.rb 在gitlab.rb中加入以下配置:

nginx['enable'] = false
三、修改nginx.conf

1、修改单独安装的nginx配置文件nginx.conf

注:本人用的是Http,配置的gitlab访问端口为8888(在etc/gitlab/gitlab.rb配置文件中配置了
external_url ‘http://xxx.xxx.xx:8888’),如端口不一样,千万记得修改!!!

http{ } 中,加入以下配置

# gitlab socket 文件地址
upstream gitlab {
  server unix:/var/opt/gitlab/gitlab-workhorse/socket;
}

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

	access_log             /usr/local/nginx/logs/gitlab_access.log;
	error_log                /usr/local/nginx/logs/gitlab_error.log;

	location /  {
		#proxy_pass     http://localhost:8080/;
		try_files $uri $uri/index.html $uri.html @gitlab;
}

	 location @gitlab {
   		 # 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;
  }
	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;

}

2、.重启使配置生效。
2.1 重启gitlab使配置生效(命令)

gitlab-ctl reconfigure

2.2 重启nginx使配置生效(命令)

service nginx restart

查看状态(命令)

gitlab-ctl status

其他指令

gitlab-ctl start
gitlab-ctl stop
gitlab-ctl restart
gitlab-ctl help
四、把Nginx设置为服务(开机自动启动)

1、创建服务脚本(创建一个nginx文件,没有后缀名,脚本内容放在这个里面)

vim /etc/init.d/nginx

2、脚本内容如下
注意:本人的nginx是安装在 /usr/local/下面的,如果你的Nginx安装在其他地方,请注意修改!

#! /bin/sh
# chkconfig: - 85 15
PATH=/usr/local/nginx/sbin/
DESC="nginx service"
NAME=nginx
DAEMON=/usr/local/nginx/sbin//$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}
do_stop() {
$DAEMON -s stop || echo -n "nginx not running"
}
do_reload() {
$DAEMON -s reload || echo -n "nginx can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
;;
reload|graceful)
echo -n "Reloading $DESC configuration..."
do_reload
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
do_stop
do_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac
exit 0

3、添加服务

chkconfig --add nginx

3.1、可尝试以下四条命令(任意目录下都可以)

service nginx start
service nginx stop
service nginx restart
service nginx reload

3.2、如果以为四条命令执行时提示权限不足,或执行不成功,可给脚本添加执行权限

chmod a+x /etc/init.d/nginx 

3.3、添加开机自行启动

chkconfig nginx on

如发现有错误,请及时评论留言,一起爬坑,一起进步!

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值