Gitlab自定义域名+SSL
in Linux with 0 comment

Gitlab自定义域名+SSL

in Linux with 0 comment

很多代码不适合放在公网上,于是自己搭建了一个Gitlab。

为gitlab设置域名和ssl

这块有两个思路:

因为我还要用到ssl,所以和现有的nginx放在一起会比较好。

但是如果只用公用的nginx转发,会导致无法 git push,这块坑还蛮多的,搞了一天。

用宝塔安装gitlab

因为本身就用的是宝塔,而宝塔有gitlab这个插件,我就不用自己造轮子了。

反向代理gitlab

直接使用反向代理,代理本地的8099端口
image

修改gitlab的域名

vim /etc/gitlab/gitlab.rb

修改

external_url 'http://iii.run'

重载 nginx, 重启gitlab

/etc/init.d/nginx reload
gitlab-ctl reconfigure
gitlab-ctl restart

如果第二个命令报错,手动到宝塔重载一下nginx

image

第三个命令依然可能出错,大概样子为

image

如果用 gitlab-ctl tail 看一下报错,一般来说,报错是这个样子的

image

两个可能的错误

file does not exist

网上查了查,似乎是宝塔的问题, 原因应该是为了防止nginx冲突, 把gitlab的nginx启动文件名改成了gitlab-web, 但有个配置文件没改造成的

修改nginx启动文件

vi /opt/gitlab/sv/nginx/run

exec chpst -P /opt/gitlab/embedded/sbin/nginx -p /var/opt/gitlab/nginx

改为

exec chpst -P /opt/gitlab/embedded/sbin/gitlab-web -p /var/opt/gitlab/nginx

这个错误会不停的出现,提醒你......

权限配置

访问会报502。原本是 nginx 用户无法访问gitlab用户的 socket 文件,用户权限配置,因人而异。粗暴地:

sudo chmod -R o+x /var/opt/gitlab/gitlab-rails

忘记默认密码

也可能是第一次忘了设置

irb(main):001:0>  user = User.where(id: '1').first

返回信息,基本所有的信息都在这里

=> #<User id: 1, email: "admin@example.com", encrypted_password: "$2a$10$lWfDMVCR9ThDtMFwEx.ql.mtbRJebHmBIvZLu5Nsd3n...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2018-12-02 03:03:38", last_sign_in_at: "2018-12-02 03:03:38", current_sign_in_ip: "58.247.170.236", last_sign_in_ip: "58.247.170.236", created_at: "2018-12-02 02:42:10", updated_at: "2018-12-02 03:03:38", name: "Administrator", admin: true, projects_limit: 10, skype: "", linkedin: "", twitter: "", authentication_token: "ddbPkmGdyjtAeKHs-wx9", theme_id: 2, bio: nil, failed_attempts: 0, locked_at: nil, username: "root", can_create_group: true, can_create_team: false, state: "active", color_scheme_id: 1, notification_level: 1, password_expires_at: nil, created_by_id: nil, last_credential_check_at: nil, avatar: nil, confirmation_token: nil, confirmed_at: "2018-12-02 02:42:10", confirmation_sent_at: nil, unconfirmed_email: nil, hide_no_ssh_key: false, website_url: "", notification_email: "admin@example.com", hide_no_password: false, password_automatically_set: false, location: nil, encrypted_otp_secret: nil, encrypted_otp_secret_iv: nil, encrypted_otp_secret_salt: nil, otp_required_for_login: false, otp_backup_codes: nil, public_email: "", dashboard: 0, project_view: 0, consumed_timestep: nil, layout: 0, hide_project_limit: false, unlock_token: nil, otp_grace_period_started_at: nil, ldap_email: false, external: false>
irb(main):003:0> user.password = 'testtest'

=> "testtest"

irb(main):004:0> user.save!

保存设置,可以猜出此时会触发一个邮件发送的JOB,告知所做变更,

Enqueued ActionMailer::DeliveryJob (Job ID: cb066b9e-0fa6-4a4a-b1e6-79d9070f18c8) to Sidekiq(mailers) with arguments: "DeviseMailer", "confirmation_instructions", "deliver_now", gid://gitlab/User/1, "U1oahRzazQw4JS5gPcq-", {:to=>"test@test.com"}
=> true

在这里貌似只能修改密码,不能修改邮箱,其次注意密码两边的是单引号

参考

https://www.liaohuqiu.net/cn/posts/non-bundled-web-server-for-gitlab/

Responses

From now on, bravely dream and run toward that dream.
陕ICP备17001447号