修改 /etc/gitlab/gitlab.rb文件
vim /etc/gitlab/gitlab.rb
如下这种写法不建议用
nginx['custom_gitlab_server_config'] = "location ~* (.*) {
deny 192.168.1.10;
allow 192.168.1.0/24;
deny all;
proxy_cache off;
proxy_pass http://gitlab-workhorse;
root html;
index index.html index.htm;}\n"
建议用如下的这种写法
nginx['custom_gitlab_server_config'] = "location ~* (.*) {\n deny 192.168.1.10;\n allow 192.168.1.0/24;\n deny all;\n proxy_cache off;\n proxy_pass http://gitlab-workhorse;\n root html;\n index index.html index.htm;}\n"
用法说明
此处修改不可以设置location /规则,因为gitlab自己的gitlab-http.conf中已经有对应的配置;
proxy_cache off;\n proxy_pass http://gitlab-workhorse;\n 这两行一定要加,不然全部报404错误
root html;\n index index.html index.htm; 这两行也要加,因为我们使用location ~* (.*)重置了所有的请求匹配
allow 192.168.1.0/24是指192.168.1.0 - 192.168.1.254的ip区段都可以访问, 如果想匹配192.168.*.*可以使用192.168.0.0/16
deny 192.168.1.10是指拒绝该主机的访问,如果有更多的主机,可以在下一行继续添加拒绝IP地址: deny 192.168.x.x 实现gitlab的IP黑名单设置
deny all除了上面的规则外,拒绝所有其他主机访问。
gitlab-ctl reconfigure
可以重启一下容器,也可以不重启。gitlab-ctl restart