gitlab Nginx 配置踩坑实际
一、需求描述
最近应导师要求需要把实验室的gitlab配置为仅指定ip可访问。之前gitlab配置的是仅内网可访问,使用的DNS也是实验室私有的DNS服务器。nginx配置就只需要用gitlab自带的就可以了。但是现在要允许外网可访问,咋办呢?那还不简单直接把对外的nginx 的流量转到gitlab的nginx不就可以了?这么一通操作之后发现不好使,老是报错。发现使用gitlab.rb的操作不太好使。需要去修改gitlab具体的nginx配置的。下面开始操作吧。
二、修改gitlab的nginx的配置
1、文件路径
[root@gitlab conf]# ps aux | grep nginx
root 1434 0.0 0.0 4228 376 ? Ss 5月06 0:00 runsv nginx
root 1439 0.0 0.0 4372 520 ? S 5月06 0:00 svlogd -tt /var/log/gitlab/nginx
root 20496 0.0 0.0 49944 3612 ? Ss 09:22 0:00 nginx: master process /opt/gitlab/embedded/sbin/nginx -p /var/opt/gitlab/nginx
[root@gitlab nginx]# ls /var/opt/gitlab/nginx
client_body_temp conf fastcgi_temp logs nginx.pid proxy_cache proxy_temp scgi_temp uwsgi_temp
[root@gitlab conf]# ls /var/opt/gitlab/nginx/conf
gitlab-http.conf nginx.conf nginx-status.conf
可以发现gitlab的nginx文件路径在 /var/opt/gitlab/nginx 下,进入该目录下 容易发现 以下几个目录。那容易得出conf目录下就是配置文件,一个一个看可以发现gitlab-http.conf 是具体的配置文件。
2、gitlab-http.conf 配置更改
server {
############## 重要#####################
listen 80; # 新增这一行
#################################
listen *:443 ssl http2;
server_name gitlab.lurious.cn;
server_tokens off; ## Don't show the nginx version number, a security best practice
## Increase this if you want to upload large attachments
## Or if you want to accept large git objects over http
client_max_body_size 0;
## Strong SSL Security
## https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html & https://cipherli.st/
################## 重要####################
ssl off; # 由 ssl on 改为 ssl off 在这里不开启 ssl 由最外层nginx配置。
#########################################
################## 略 ####################
}
3、重启gitlab的nginx
gitlab-ctl restart nginx
特别注意: 这里是重启nginx 一定不要落下 最后的nginx
到这里 gitlab的配置就完成了。
二、配置对外nginx
这里就比较简单了,只需要把转向 gitlab所在机子 的80端口即可 如192.168.23.12:80
三、配置IP白名单
location / {
include env/proxy.conf;
proxy_pass http://xxx/xxx;
# 添加网关白名单
allow 192.168.8.0/24;
deny all;
}
添加白名单 比较容易,就使用 allow和deny两个参数就可以了。
好了 完成,交作业啦!!!!!!!!!