Changed external_url, how to redirect old url calls to new subdomain

How can I define a redirect rule for nginx in gitlab.rb?

Here’s my scenario:

  1. I have gitlab running well with letsencrypt certificates on:
    tracker.domainhere.com

  2. I want to move to: gitlab.domainhere.com

  3. I modified giltab.rb external_url and reconfigure successfully, now everything runs on the new domain.

Problem:
A lot of people will keep calling the old URL which now have no valid certificates and show a very ugly message.

I’m trying to add a nginx redirect from every call tracker.domain.com into gitlab.domain.com

I cannot do that directly as nginx config is managed by gitlab, any ideas how to do this in /etc/gilab/gitlab.rb

Thanks

Hi,
Redirect rule for Nginx in gitlab.rb to redirect calls from tracker.domainhere.com to gitlab.domainhere.com , you can add a custom Nginx configuration snippet using the nginx[‘custom_gitlab_server_config’] option.

Now you can open the gitlab.rb configuration file, usually located at /etc/gitlab/gitlab.rb, for editing.
Uncomment the nginx[‘custom_gitlab_server_config’] and add this below line

nginx['custom_gitlab_server_config'] = "location / { return 301 https://gitlab.domainhere.com$request_uri; }"
Replace gitlab.domainhere.com with your new domain then Reconfigure GitLab.
sudo gitlab-ctl reconfigure
After above changes Nginx will redirect all calls to tracker.domainhere.com to gitlab.domainhere.com with a 301 redirect response. once done
You can verify url on any online tool such as Redirectchecker.com for its redirection chain.