Create a gist now

Instantly share code, notes, and snippets.

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

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

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

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

@0X1A
0X1A commented Jul 25, 2013

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

@zoffixznet

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
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

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

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
omps commented Apr 7, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment