Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Apache vhost config for gitlab

unicorn config file

Edit file /home/gitlab/gitlab/config/unicorn.rb

Find line listen "#{app_dir}/tmp/sockets/gitlab.socket" and comment it. Uncomment line listen "127.0.0.1:8080"

required modules for apache

  • sudo a2enmod proxy
  • sudo a2enmod proxy_balancer
  • sudo a2enmod proxy_http
  • sudo a2enmod rewrite
<VirtualHost *:80>
ServerName git.domain.com
# Point this to your public folder of teambox
DocumentRoot /home/gitlab/gitlab
RewriteEngine On
<Proxy balancer://unicornservers>
BalancerMember http://127.0.0.1:8080
</Proxy>
# Redirect all non-static requests to thin
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L]
ProxyPass / balancer://unicornservers/
ProxyPassReverse / balancer://unicornservers/
ProxyPreserveHost on
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
# Custom log file locations
ErrorLog /var/log/apache2/gitlab_error.log
CustomLog /var/log/apache2/gitlab_access.log combined
</VirtualHost>
@steve-todorov

This comment has been minimized.

Show comment Hide comment
@steve-todorov

steve-todorov Feb 11, 2013

You do not need a load balancer to make this work.
You can simply use proxy pass:

<VirtualHost *:80>
    ....
    ProxyRequests     Off
    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:8080/
    <Location />
        ProxyPassReverse /
        Order deny,allow
        Allow from all
    </Location>
    ....
</VirtualHost>

(https://gist.github.com/steve-todorov/4758707)

You do not need a load balancer to make this work.
You can simply use proxy pass:

<VirtualHost *:80>
    ....
    ProxyRequests     Off
    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:8080/
    <Location />
        ProxyPassReverse /
        Order deny,allow
        Allow from all
    </Location>
    ....
</VirtualHost>

(https://gist.github.com/steve-todorov/4758707)

@carlosspohr

This comment has been minimized.

Show comment Hide comment
@carlosspohr

carlosspohr Apr 30, 2013

I'm just only make correct Apache route for Gitlab with this configure:

https://gist.github.com/carlosjrcabello/5486422

I'm just only make correct Apache route for Gitlab with this configure:

https://gist.github.com/carlosjrcabello/5486422

@0X1A

This comment has been minimized.

Show comment Hide comment
@0X1A

0X1A Jul 25, 2013

Puma replaced unicorn, does anything need to be changed in puma for this to work correctly?

0X1A commented Jul 25, 2013

Puma replaced unicorn, does anything need to be changed in puma for this to work correctly?

@zoffixznet

This comment has been minimized.

Show comment Hide comment
@zoffixznet

zoffixznet Nov 25, 2013

Thanks a lot. This is my gitlab.conf that did the trick (note the different version numbers in /gems/ lines):

   LoadModule passenger_module /usr/local/lib/ruby/gems/2.0.0/gems/passenger-4.0.25/buildout/apache2/mod_passenger.so
   PassengerRoot /usr/local/lib/ruby/gems/2.0.0/gems/passenger-4.0.25
   PassengerDefaultRuby /usr/local/bin/ruby

<VirtualHost *:80>
        ServerName gitlab
        # Point this to your public folder of teambox
        DocumentRoot /home/git/gitlab/public
        ProxyPass /gitlab/ http://127.0.0.1:8081/
        ProxyPassReverse /gitlab/ http://127.0.0.1:8081/
        ProxyPreserveHost On

        # Custom log file locations
        ErrorLog /var/log/apache2/gitlab_error.log
        CustomLog /var/log/apache2/gitlab_access.log combined
</VirtualHost>

Thanks a lot. This is my gitlab.conf that did the trick (note the different version numbers in /gems/ lines):

   LoadModule passenger_module /usr/local/lib/ruby/gems/2.0.0/gems/passenger-4.0.25/buildout/apache2/mod_passenger.so
   PassengerRoot /usr/local/lib/ruby/gems/2.0.0/gems/passenger-4.0.25
   PassengerDefaultRuby /usr/local/bin/ruby

<VirtualHost *:80>
        ServerName gitlab
        # Point this to your public folder of teambox
        DocumentRoot /home/git/gitlab/public
        ProxyPass /gitlab/ http://127.0.0.1:8081/
        ProxyPassReverse /gitlab/ http://127.0.0.1:8081/
        ProxyPreserveHost On

        # Custom log file locations
        ErrorLog /var/log/apache2/gitlab_error.log
        CustomLog /var/log/apache2/gitlab_access.log combined
</VirtualHost>
@CSchulz

This comment has been minimized.

Show comment Hide comment
@CSchulz

CSchulz Jun 9, 2014

In general you don't need the passenger when you are using unicorn. You just need a proxy and a workaround for try files:
(See https://gitlab.com/gitlab-org/gitlab-recipes/tree/master/web-server/apache)

CSchulz commented Jun 9, 2014

In general you don't need the passenger when you are using unicorn. You just need a proxy and a workaround for try files:
(See https://gitlab.com/gitlab-org/gitlab-recipes/tree/master/web-server/apache)

@leftclickben

This comment has been minimized.

Show comment Hide comment
@leftclickben

leftclickben Sep 12, 2014

Note: For apache 2.4 the Order / Allow / Deny syntax has changed to Require syntax. I also agree with comments above about not needing a load balancer, or passenger. In fact the config is very simple, this is my file which works on 2.4.7:

<VirtualHost *:80>
    ServerName git.domain.com.au
    ServerAlias git  # this allows short name access within the domain
    DocumentRoot /var/opt/gitlab

    RewriteEngine On
    ProxyRequests Off
    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:8888/

    <Location />
        ProxyPassReverse /
        Require all granted   # Apache 2.4
    </Location>

    # Custom log file locations
    ErrorLog /var/log/apache2/gitlab_error.log
    CustomLog /var/log/apache2/gitlab_access.log combined
</VirtualHost>

Note: For apache 2.4 the Order / Allow / Deny syntax has changed to Require syntax. I also agree with comments above about not needing a load balancer, or passenger. In fact the config is very simple, this is my file which works on 2.4.7:

<VirtualHost *:80>
    ServerName git.domain.com.au
    ServerAlias git  # this allows short name access within the domain
    DocumentRoot /var/opt/gitlab

    RewriteEngine On
    ProxyRequests Off
    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:8888/

    <Location />
        ProxyPassReverse /
        Require all granted   # Apache 2.4
    </Location>

    # Custom log file locations
    ErrorLog /var/log/apache2/gitlab_error.log
    CustomLog /var/log/apache2/gitlab_access.log combined
</VirtualHost>
@setiawand

This comment has been minimized.

Show comment Hide comment
@setiawand

setiawand Mar 18, 2015

hello, i want to use apache for gitlab, and got this gitlab.yml like this

GitLab settings

gitlab:
## Web server settings (note: host is the FQDN, do not include http://)
host: 54.xxx.xxx.xx
port: 80
https: false

and on unicorn.rb

What ports/sockets to listen on, and what options for them.

listen "127.0.0.1:8080", :tcp_nopush => true
listen "/var/opt/gitlab/gitlab-rails/sockets/gitlab.socket", :backlog => 1024

working_directory '/var/opt/gitlab/gitlab-rails/working'

so if i want to switch to apache only comment this line ?

listen "/var/opt/gitlab/gitlab-rails/sockets/gitlab.socket", :backlog => 1024

and put this lines on httpd.conf
<VirtualHost *:80>
ServerName git.domain.com.au
ServerAlias git # this allows short name access within the domain
DocumentRoot /var/opt/gitlab

RewriteEngine On
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8888/

<Location />
    ProxyPassReverse /
    Require all granted   # Apache 2.4
</Location>

# Custom log file locations
ErrorLog /var/log/apache2/gitlab_error.log
CustomLog /var/log/apache2/gitlab_access.log combined

how about gitlab.yml setting
there is port config
port: 80

do i need to comment it ?

thanks a lot :)

hello, i want to use apache for gitlab, and got this gitlab.yml like this

GitLab settings

gitlab:
## Web server settings (note: host is the FQDN, do not include http://)
host: 54.xxx.xxx.xx
port: 80
https: false

and on unicorn.rb

What ports/sockets to listen on, and what options for them.

listen "127.0.0.1:8080", :tcp_nopush => true
listen "/var/opt/gitlab/gitlab-rails/sockets/gitlab.socket", :backlog => 1024

working_directory '/var/opt/gitlab/gitlab-rails/working'

so if i want to switch to apache only comment this line ?

listen "/var/opt/gitlab/gitlab-rails/sockets/gitlab.socket", :backlog => 1024

and put this lines on httpd.conf
<VirtualHost *:80>
ServerName git.domain.com.au
ServerAlias git # this allows short name access within the domain
DocumentRoot /var/opt/gitlab

RewriteEngine On
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8888/

<Location />
    ProxyPassReverse /
    Require all granted   # Apache 2.4
</Location>

# Custom log file locations
ErrorLog /var/log/apache2/gitlab_error.log
CustomLog /var/log/apache2/gitlab_access.log combined

how about gitlab.yml setting
there is port config
port: 80

do i need to comment it ?

thanks a lot :)

@omps

This comment has been minimized.

Show comment Hide comment
@omps

omps Apr 7, 2016

all my subdomains stopped working and everysubdomin is now pointed to my gitlab url

omps commented Apr 7, 2016

all my subdomains stopped working and everysubdomin is now pointed to my gitlab url

@chaiwei

This comment has been minimized.

Show comment Hide comment
@chaiwei

chaiwei Jan 6, 2017

@omps Check your port 80 netstat -plnt | grep ':80' whether is overwrite by Nginx, It happens to my local server as well. My original webserver is running on apache2.4 after installed gitlab all website doesn't work anymore.

tcp        0      0 0.0.0.0:8060            0.0.0.0:*               LISTEN      16929/nginx
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      16884/config.ru
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      16929/nginx

https://kevingoedecke.me/2015/09/17/setup-gitlab-on-debian-7-with-existing-apache-webserver/
I follow the tutorial on this website to update it the gitlab.rb configuration file and now is back to

tcp6       0      0 :::8080                 :::*                    LISTEN      1233/apache2
tcp6       0      0 :::80                   :::*                    LISTEN      1233/apache2
tcp6       0      0 :::8081                 :::*                    LISTEN      1233/apache2

chaiwei commented Jan 6, 2017

@omps Check your port 80 netstat -plnt | grep ':80' whether is overwrite by Nginx, It happens to my local server as well. My original webserver is running on apache2.4 after installed gitlab all website doesn't work anymore.

tcp        0      0 0.0.0.0:8060            0.0.0.0:*               LISTEN      16929/nginx
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      16884/config.ru
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      16929/nginx

https://kevingoedecke.me/2015/09/17/setup-gitlab-on-debian-7-with-existing-apache-webserver/
I follow the tutorial on this website to update it the gitlab.rb configuration file and now is back to

tcp6       0      0 :::8080                 :::*                    LISTEN      1233/apache2
tcp6       0      0 :::80                   :::*                    LISTEN      1233/apache2
tcp6       0      0 :::8081                 :::*                    LISTEN      1233/apache2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment