Moving GitLab to a non-standard port

Written by:
Posted in: ,
Published: April 25, 2014

We love GitLab and use it for a ton of our internal (and client) projects. We recently had to move it from HTTP port 80 and SSH port 22 to a non-standard ports and we were unable to find sufficient documentation on this process, causing us to waste more hours than I’d like to admit figuring it out.

We used port 8081 for the HTTP traffic and 2222 for SSH. Before doing these steps make sure you have the new ports open on your router if you need to access them from outside your local network, etc.

So for anyone who is interested here’s the skinny:

  1. Modify  /home/git/gitlab/gitlab.yml
    Add (or uncomment) the bold line below for your new HTTP port:
    [code]
    ## GitLab settings
    gitlab:
    ## Web server settings
    host: your.hostname
    port: 8081
    https: false
    [/code]
    Next, add (or uncomment) the line below for your new SSH port:
    [code]
    # If you use non-standard ssh port you need to specify it

    ssh_port: 2222
    [/code]

  2. Modify  /home/git/gitlab-shell/config.yml to use the new HTTP port: 

    [code]
    # Url to gitlab instance. Used for api calls. Should end with a slash.
    gitlab_url: “http://your.hostname:8081/”
    [/code]

  3. Modify /etc/nginx/sites-available/gitlab
    [code]
    listen *:8081 default_server; # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea
    [/code]
  4. Modify /etc/ssh/sshd_config
    [code]
    # What ports, IPs and protocols we listen for
    Port 2222
    [/code]
  5. Restart SSH, restart GitLab, restart nginx:
    [code]
    sudo service ssh restart
    sudo service gitlab restart
    sudo service nginx restart
    [/code]
  6. Test GitLab:
    [code]
    sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
    sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
    [/code]
  7. Update the remote origins for your repos to use the new port:
    [code]
    ssh://git@your.hostname:8081/repo_name
    [/code]

Hope this helps someone save a little time!