为了方便外部访问,所以一开始吧gitlab配置成了https,再通过反向代理和TCP隧道从外部网络服务器反向代理到本地应用服务器,由于本地应用服务器和工作的PC在局域网里面,如果这个时候通过通过外部访问仓库就会很鸡肋,而且gitlab runner如果通过https进行注册,有些时候会因为网络问题导致流水线失败。所以这里讲一下这么让gitlab同时开启http和https模式

1、修改Docker暴露端口

将gitlab的443和80都暴露出来

2、将gitlab配置成https模式

1
nano /etc/gitlab/gitlab.rb

修改 external_url

1
2
3
...
external_url 'https://xxx.xxx'
...

然后执行 gitlab-ctl reconfigure ,此时会在 /var/opt/gitlab/nginx/conf 生成文件gitlab-https.conf \

复制一份出来

1
cp /var/opt/gitlab/nginx/conf/gitlab-https.conf /var/opt/gitlab/nginx/conf/gitlab-http.conf

把https的配置文件修改成http的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
listen *:443 ssl http2; -> listen *:80;
...
## Strong SSL Security
## https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html & https://cipherli.st/
# ssl_certificate /etc/gitlab/ssl/xxx.xxx.crt; #注释掉
# ssl_certificate_key /etc/gitlab/ssl/xxx.xxx.key; #注释掉

# GitLab needs backwards compatible ciphers to retain compatibility with Java IDEs
# ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384'; #注释掉
# ssl_protocols TLSv1.2 TLSv1.3; #注释掉
# ssl_prefer_server_ciphers off; #注释掉
# ssl_session_cache shared:SSL:10m; #注释掉
# ssl_session_tickets off; #注释掉
# ssl_session_timeout 1d; #注释掉
...
proxy_set_header Host $http_host_with_default;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
# proxy_set_header X-Forwarded-Ssl on; #注释掉
# proxy_set_header X-Forwarded-Proto https; #注释掉
...

把修改完的配置文件include 到 /var/opt/gitlab/nginx/conf/nginx.conf

修改 gitlab.rb 在nginx配置添加

1
2
3
4
5
...
# nginx['custom_gitlab_server_config'] = "location ^~ /foo-namespace/bar-project/raw/ {\n deny all;\n}\n"
nginx['custom_nginx_config'] = "include /var/opt/gitlab/nginx/conf/gitlab-http.conf;"
# nginx['proxy_read_timeout'] = 3600
...