Search code examples
http-redirectnginxgitlabgitlab-omnibus

Gitlab Omnibus: how to redirect all requests to another domain


I migrated my Gitlab to a new domain. I'd like to redirect all HTTP requests from the old URL to the new one. Both domains currently point to the same server (using A DNS records).

I use Gitlab Omnibus package, with the bundled nginx install. How to do this?


Solution

  • First, create /etc/nginx/conf.d/redirect.conf:

    server {
      listen 80;
      server_name old-gitlab.mydomain.com;
      rewrite ^/(.*)$ http://new-gitlab.mydomain.com/$1 permanent;
    }
    

    (if the /etc/nginx/conf.d/ path does not exist, go ahead and create it)

    Now edit the configuration file at /etc/gitlab/gitlab.rb to add the following line:

    nginx['custom_nginx_config'] = "include /etc/nginx/conf.d/redirect.conf;"
    

    Finally, run gitlab-ctl reconfigure to rewrite the nginx configuration and restart nginx.