1987WEB视界-分享互联网热门产品和行业

您现在的位置是:首页 > 域名 > 正文

域名

搭建gitlab自定义域名

1987web2022-10-06域名545
搭建gitlab自定义域名

搭建gitlab自定义域名

Gitlab 内置了 nginx,所以配置nginx代理服务器转向GitLab内置的nginx

参见官网:https://docs.gitlab.com/omnibus/settings/configuration.htmlconfiguring-the-external-url-for-gitlab

配置Gitlab

编辑GitLab配置文件

vim/etc/gitlab/gitlab.rb

修改端口监听

nginx[listen_port] = 8800

修改Gitlab域名

external_urlhttp://www.example.com

使配置生效

配置生效sudo gitlab-ctl reconfigure•重启gitlab-ctl restart

配置nginx

配置内容如下

server{listen80;外网访问域名,此域名是提供给最终用户的访问地址server_name域名;location/ {客户端请求正文的最大允许大小这个大小的非常重要,如果git版本库里有大文件,设置的太小,文件push会失败,根据情况调整client_max_body_size50m;安全相关 header禁止网站被嵌入到其它网页中,如:iframe、embed等,SAMEORIGIN表示该页面仅能在相同域名页面的iframe中展示add_headerX-Frame-Options "SAMEORIGIN" always;当检测到XSS攻击时阻止页面加载add_headerX-XSS-Protection "1; mode=block" always;禁止请求类型为style和script时,但MIME类型却不为text/css和JavaScript的请求add_headerX-Content-Type-Options "nosniff" always;proxy_redirectoff;以下确保 gitlab中项目的 url 是域名而不是 http://git,不可缺少proxy_set_headerHost $host;proxy_set_headerX-Real-IP $remote_addr;proxy_set_headerX-Forwarded-For $proxy_add_x_forwarded_for;反向代理到 gitlab 内置的 nginxproxy_passhttp://www.example.com:8800;indexindex.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") {return403;}}

重载nginx

sudo/usr/local/nginx/sbin/nginx -tsudo/usr/local/nginx/sbin/nginx -s reloadsudosystemctl reload nginx

配置GitLab项目默认域名

编辑gitlab.yml配置文件

vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml

修改如下内容

gitlab:HTTP/S方式拉取项目时的域名host:http://www.example.comport:80https:falseSSH方式拉取项目时的域名ssh_host:www.example.com

其它

安装GitLab

迁移/备份/恢复GitLab

修改GitLab的root用户密码

未完待续