GitLab私服搭建

此方式针对Gitlab服务部署在内网,通过域名在公网访问。

因Frp的HTTPS方式一直没有配置成功,所以使用的是Nginx转发的形式。如有大佬不吝赐教,万分感激。

GitLab搭建

version: '3.6'
services:
  web:
    image: 'gitlab/gitlab-ee:latest'
    restart: always
    hostname: 'gitlab.wowaili.com'
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://gitlab.wowaili.com'
        gitlab_rails['time_zone'] = 'Asia/Shanghai'
        gitlab_rails['gitlab_shell_ssh_port'] = 2222
    ports:
      - '80:80'
      - '2222:22'
      - '443:443'
    volumes:
      - ./data/config:/etc/gitlab
      - ./data/logs:/var/log/gitlab
      - ./data/data:/var/opt/gitlab
    shm_size: '256m'

内网穿透 frpc配置

[common]
server_addr = xxx.xxx.xxx.xxx
server_port = 7000
token = xxxxxxxx

[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 2222
remote_port = 2222

[web]
type = http
local_port = 80
custom_domains = gitlab.wowaili.com

frpc.ini配置

公网服务器转发

server {
    client_max_body_size 500m;
    listen       80 default_server;
    listen       [::]:80 default_server;
    location / {
        proxy_pass    http://127.0.0.1:30000/;
        proxy_set_header    Host    $host;
        proxy_set_header    Remote_Addr    $remote_addr;
        proxy_set_header    X-Real-IP    $remote_addr;
        proxy_set_header    X-Forwarded-For    $remote_addr;
    }
    
}
default.conf配置, 该配置作用为转发所有请求到内网。
server {
    listen       80;
    server_name  gitlab.wowaili.com;

    access_log  /var/log/nginx/gitlab.wowaili.com.http.access.log  main;
    error_log  /var/log/nginx/gitlab.wowaili.com.http.error.log;

    rewrite ^(.*)$ https://${server_name}$1 permanent;
}

server {
    listen       443 ssl;
    server_name  gitlab.wowaili.com;

    # For https
    ssl_certificate     ssl/gitlab.wowaili.com_bundle.crt;
    ssl_certificate_key ssl/gitlab.wowaili.com.key;

    # ssl验证相关配置
    ssl_session_cache   shared:SSL:10m;
    ssl_session_timeout 10m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK';
    ssl_prefer_server_ciphers on;

    access_log  /var/log/nginx/gitlab.wowaili.com.https.access.log  main;
    error_log  /var/log/nginx/gitlab.wowaili.com.https.error.log;

    location / {
        proxy_pass http://gitlab.wowaili.com:30000;
        proxy_set_header HOST $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

}
Tip:关注点在 `location` 中(30行),需要配置代理地址为 `frpc.ini` 中的地址且代理端口应与 `frps.ini` 一致。

frps.ini配置关注点

优化

以上步骤执行完成后,点击克隆按钮,即可拉取代码。但是Http方式使用的是http协议,可通过修改 `通用` -> `自定义HTTP(S)协议Git克隆URL` 指定为https。

配置

https