71

How do I change gitlab's default port 80 to a custom port number?

There are two approaches I've tried:

Set the port in /etc/gitlab/gitlab.rb

external_port "8888"

Then run reconfigure:

gitlab-ctl reconfigure

Set port in /var/opt/gitlab/gitlab-rails/etc/gitlab.yml

production: &base
  #
  # 1. GitLab app settings
  # ==========================

  ## GitLab settings
  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: gitlab.blitting.com
    port: 8888
    https: false

Then restart gitlab

gitlab-ctl stop
gitlab-ctl start

With both of these, gitlab continues to run on the default 80 port number.

Jason Sturges
  • 833
  • 1
  • 9
  • 9

8 Answers8

82

Chad Carbert answer still applies but just want to add extra for version 7.0.0.

Open "/etc/gitlab/gitlab.rb" in your text editor where currently I have external_url http://127.0.0.1/ or similar to that. I may need to change external_url with dns including port number (eg. 'http://gitlab.com.local:81/') then reconfigure using command "sudo gitlab-ctl reconfigure" Gitlab is now working on port 81.

Step by step:

  1. sudo -e /etc/gitlab/gitlab.rb
  2. Change external_url from yourdomain.com to yourdomain.com:9999
    9999 -> Port you want it to run
  3. sudo gitlab-ctl reconfigure
Pritesh Patel
  • 935
  • 8
  • 10
  • 1
    For me gitlab is now accessible through both 8080 and 8081 (the port I added). Any idea how I can free up 8080? – DaSh Oct 02 '14 at 23:31
  • 2
    Stopping and starting it again solved the issue. – DaSh Oct 02 '14 at 23:45
  • 1
    If this doesn't work, check the logs using `gitlab-ctl tail` to find if the ports collide. – dusan Oct 28 '14 at 15:19
  • Is there an alternative command for `gitlab-ctl reconfigure` if I don't have `gitlab-ctl`? Just restarting should do, right? – icedwater Feb 03 '15 at 06:37
  • I think no, yes restarting server should do. – Pritesh Patel Feb 05 '15 at 06:08
  • I can't believe it is this simple. In my case, Apache was already the server on port 80 hence the need for a port. – pkanane Jun 04 '15 at 13:43
  • 1
    See the "#unicorn['port'] = '8080'" value in the config file. – emeraldjava Oct 29 '15 at 17:44
  • I have bitnami virtual machine, when I do the edit above it works. But after restarting virtual machine the file gitlab.rb would be changed to the previous value!!! – kamil Jan 10 '18 at 07:22
  • @kamil I am not much aware of bitnami but it works on docker (not sure) and probably overwriting gitlab.rb every time when configure. It must have other workarounds to set your own gitlab.rb – Pritesh Patel Jan 10 '18 at 11:59
  • any suggestion on how to set external url and not loosing it on restart, note that there might be a script getting internal ip address and changing it in gitlab.rb – kamil Jan 11 '18 at 07:31
  • I'm using a dockerized gitlab (v11.1.4) and it doesn't work! – Benyamin Jafari Jan 11 '22 at 10:00
7

Very simple way to change defaults port number

gitlab-ctl stop

Edit the file in centos or linux: /var/opt/gitlab/nginx/conf/gitlab-http.conf
Change listen *:80; to what you want Ex:- 90

Then

Don't run the command: gitlab-ctl reconfigure
If gitlab-ctl reconfigure it configured gitlab by defaults and remove changes.

So only run: gitlab-ctl start

Benyamin Jafari
  • 213
  • 2
  • 5
Rahul Jain
  • 71
  • 1
  • 1
6

I'm also having this same issue. I don't have my gitlab.rb in the same location as you, but do have it installed via dpkg at the /opt path you mentioned.

If you've installed it via the package, all self-contained in that /opt directory, then you might find changing the port at :

  • /opt/gitlab/embedded/conf/nginx.conf
  • /opt/gitlab/embedded/cookbooks/gitlab/templates/default/nginx-gitlab-http.conf.erb

Issue #6581: .deb package install on Ubuntu 12.04 - Port number in gitlab.yml file is ignored

Cristian Ciupitu
  • 6,226
  • 2
  • 41
  • 55
Chad Carbert
  • 161
  • 2
  • How did this help? I'm still not getting anywhere with this - gitlab is insisting on using port 80 - which it can't because apache is already using it. Any specifics about what you did? Changing ports in those files did nothing. – Hippyjim Aug 19 '14 at 13:43
5

With Ubuntu 17.04 and gitlab-ce 9.2.2, on local network

These steps worked for me:

  1. Edit gitlab.rb file.

sudo nano /etc/gitlab/gitlab.rb

  1. Add your optional listen port to end of file.

nginx['listen_port'] = 8181

  1. Stop apache if needed, and reconfigure gitlab

sudo service apache2 stop sudo gitlab-ctl reconfigure

  1. Start apache if you stop that.

sudo service apache2 start

  1. Finished, now gitlab is available on your ip address with selected port.

'http://localhost:8181'

Cory Knutson
  • 1,866
  • 12
  • 20
HexboY
  • 151
  • 1
  • 3
4

My main issue was that new users were not getting the custom port number in the emails that the system sent. Otherwise, manually writing the custom port in the address bar led users to the Gitlab install.

I did this install on Ubuntu 14.04 instead of the Omnibus. So somehow I don't have gitlab-ctl. (It exists in /usr/bin, but the target of the symlink wasn't installed somehow. I'll fix that separately if I really have to.)

Anyway, I used a variant of the second approach, writing the correct port into /home/git/gitlab/config/gitlab.yml:

production: &base
  #
  # 1. GitLab app settings
  # ==========================

  ## GitLab settings
  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: my.gitlab.host.com
    port: 3722

Since I don't have gitlab-ctl, I used service:

sudo service gitlab restart

That worked for me. New users that I sent the email to received a link which contained the correct URL.

icedwater
  • 151
  • 6
2

In Amazon Linux using the Centos 6 package I had to configure the file:

/opt/gitlab/embedded/cookbooks/gitlab/attributes/default.rb

and then do the

gitlab-ctl reconfigure 

command to finally get the port change.

Paco Zarate
  • 121
  • 1
2

I'm using Gitlab 7.5.3 omnibus 5.2.1 ci on Debian Squeeze. To change the default port for nginx add the _gitlab_port_ to /etc/gitlab/gitlab.rb:

My /etc/gitlab/gitlab.rb:

external_url = 'gitlab.example.org'
gitlab_rails['gitlab_port'] = 12345

After changing the port, you have to call gitlab-ctl reconfigure and gitlab-ctl restart in your command line.

lszrh
  • 683
  • 3
  • 7
  • 15
0

You must change the external_url value on Gitlab configuration file.

Follow these steps:

  1. Edit config file by run this command
sudo nano /etc/gitlab/gitlab.rb
  1. Find the external_url and change to your URL and port

Change external_url

  1. Exit and save the change (ctrl + X)
  2. Run this command to reconfiguration the Gitlab local server
sudo gitlab-ctl reconfigure

If you use the webserver like Nginx you must change the external port from the reverse proxy in the configuration of Nginx.

Amintabar
  • 101
  • 2