gitlab配置

一、 安装gitlab

  1. ubuntu
下载:wget --content-disposition https://packages.gitlab.com/gitlab/gitlab-ce/packages/ubuntu/xenial/gitlab-ce_12.1.4-ce.0_amd64.deb/download.deb
安装 dpkg -i 安装包名称
  1. centos
下载: wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm
// 没有rpm需要安装
yum -y install wget
安装:rpm -i 安装包名称 

二、修改gitlab配置文件 vi /etc/gitlab/gitlab.rb

external_url 'http://IP地址:端口号'     // 端口号需要在防火墙放行
修改完成后执行命令更新:gitlab-ctl reconfigure

三、 修改clone、push路径 vi /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml

## GitLab settings
  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: 域名 || ip
    port: 80 || 上方配置的端口号
    https: false
     # Uncommment this line below if your ssh host is different from HTTP/HTTPS one
    # (you'd obviously need to replace ssh.host_example.com with your own host).
    # Otherwise, ssh host will be set to the `host:` value above
    ssh_host: 域名 || ip
 Todo: 执行gitlab-ctl reconfigure的话目前我这边会把上面配置的重置,所以这块改完无需重新加载配置。想要解决的话应该需要在/etc/gitlab/gitlab.rb以及其他相关文件的url改为域名,目前还没有试
 在上方执行完后启用gitlab:  gitlab-ctl restart
 启用后在可以用第二步配置的external_url地址打开了,打开后会先对root用户强制修改密码

四、 nginx配置反向代理

server {
       listen 80;
       # 外网访问域名,此域名是提供给最终用户的访问地址
       server_name 域名 || id地址;

      location / {
            # 客户端请求正文的最大允许大小
            # 这个大小的非常重要,如果git版本库里有大文件,设置的太小,文件push会失败,根据情况调整
            client_max_body_size 50m;

            # 安全相关 header
            # 禁止网站被嵌入到其它网页中,如:iframe、embed等,SAMEORIGIN表示该页面仅能在相同域名页面的iframe中展示
            add_header X-Frame-Options "SAMEORIGIN" always; 
            # 当检测到XSS攻击时阻止页面加载
            add_header X-XSS-Protection "1; mode=block" always;
            # 禁止请求类型为style和script时,但MIME类型却不为text/css和JavaScript的请求
            add_header X-Content-Type-Options "nosniff" always;

            proxy_redirect off;
            #以下确保 gitlab中项目的 url 是域名而不是 http://git,不可缺少
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            # 反向代理到 gitlab 内置的 nginx
            proxy_pass http://ip或域名:端口号;
            index index.html index.htm;
      }
      # 防止爬虫抓取 
           if ($http_user_agent ~* "360Spider|JikeSpider|Spider|spider|bot|Bot|2345Explorer|curl|wget|webZIP|qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot|NSPlayer|bingbot") { 
                return 403; 
           }
}

五. nginx重载配置和重启

posted @ 2022-11-04 10:23  walxl  阅读(367)  评论(0编辑  收藏  举报