I\'m attempting to set up gitlab so that it is accessible through a subdirectory of an existing apache server, example.com/gitlab
, for example. I am trying to use p
An update on user1258056's post :
On recent releases of Gitlab (I'm using 10.0.3), the proposed solution leads to assets not being loaded (Error 401 : Not Authorized)
To fix this, add the following lines in /etc/gitlab/gitlab.rb :
unicorn['port'] = 8081
gitlab_workhorse['listen_addr'] ="127.0.0.1:8181"
gitlab_workhorse['listen_network'] = "tcp"
And change /etc/apache2/apache2.conf as follow :
ProxyPass /gitlab/assets/ http://127.0.0.1:8181/gitlab/assets/
ProxyPassReverse /gitlab/assets/ http://127.0.0.1:8181/gitlab/assets/
ProxyPass /gitlab/ http://127.0.0.1:8081/gitlab/
ProxyPassReverse /gitlab/ http://127.0.0.1:8081/gitlab/
ProxyPass /gitlab http://127.0.0.1:8081/gitlab
ProxyPassReverse /gitlab http://127.0.0.1:8081/gitlab
This leads to assets request being dispatched to the Workhorse component (port 8181), while other requests go through the usual path (port 8081)
Running Gitlab in a subdirectory is not officially supported, but works fine (I'm currently running an instance). I don't know anything about Passenger, but this is how you run it using unicorn and a frontend proxy:
You need to set you subdirectory in three places (to cite the default gitlab.yml):
# Uncomment and customize the last line to run in a non-root path
# WARNING: This feature is no longer supported
# Note that three settings need to be changed for this to work.
# 1) In your application.rb file: config.relative_url_root = "/gitlab"
# 2) In your gitlab.yml file: relative_url_root: /gitlab
# 3) In your unicorn.rb: ENV['RAILS_RELATIVE_URL_ROOT']
#
relative_url_root: /gitlab
I just put the ENV['RAILS_RELATIVE_URL_ROOT'] '/gitlab'
somewhere at the top in unicorn.rb, as there is no "default" place.
After this, you need to start sidekiq (the background job deamon) and unicorn (the webserver for gitlab) as described in the installation documentation. The supplied init script works really well.
Finally you need to setup your apache webserver to proxy requests to the backend unicorn instance. mod_proxy configured as a reverse proxy should do the job. (Arthurs answer has a bit more detail on this part)
If you (or someone comming from google) want to use nginx as a frontend proxy, this is the configuration I use:
location /gitlab {
alias /home/git/gitlab/public;
access_log /var/log/nginx/gitlab_access.log;
error_log /var/log/nginx/gitlab_error.log;
# serve static files from defined root folder;.
# @gitlab is a named location for the upstream fallback, see below
try_files $uri $uri/index.html $uri.html @gitlab;
}
# if a file, which is not found in the root folder is requested,
# then the proxy pass the request to the upsteam (gitlab unicorn)
location @gitlab {
proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
proxy_redirect off;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://gitlab;
access_log /var/log/nginx/gitlab_access.log;
error_log /var/log/nginx/gitlab_error.log;
}
I use gitlab & nginx. use gitlab in subdir has many problems (or bugs). I use gitlab.example.com (easy to configure, easy to remember), not example.com/gitlab.
I did the following to get gitlab 6.2.2 available in a sub-directory with Apache and a LAMP environment:
enable the following apache modules:
sudo a2enmod proxy
sudo a2enmod proxy_balancer
sudo a2enmod proxy_http
sudo a2enmod rewrite
right from the documentation, do the following:
# 1) In your application.rb file: config.relative_url_root = "/gitlab"
# 2) In your gitlab.yml file: relative_url_root: /gitlab
# 3) In your unicorn.rb: ENV['RAILS_RELATIVE_URL_ROOT'] = "/gitlab"
in /etc/apache2/mod-available/proxy.conf:
ProxyRequests On
ProxyPreserveHost on
<Proxy *>
AddDefaultCharset off
Order deny,allow
Allow from all
AllowOverride All
</Proxy>
in /etc/apache2/apache2.conf:
ProxyPass /gitlab/ http://127.0.0.1:8080/gitlab/
ProxyPassReverse /gitlab/ http://127.0.0.1:8080/gitlab/
ProxyPass /gitlab http://127.0.0.1:8080/gitlab
ProxyPassReverse /gitlab http://127.0.0.1:8080/gitlab
ProxyPass /assets http://127.0.0.1:8080/gitlab/assets
ProxyPassReverse /assets http://127.0.0.1:8080/gitlab/assets
I don't think that Passenger is the easiest way to configure Apache for GitLab. Using a local reverse proxy is actually more simple.
The lastest version of GitLab (6.0) is using Unicorn, but it almost the same with Puma.
In your config/unicorn.rb
file, comment listen
directive and add:
listen "127.0.0.1:9242"
In your Apache configuration, you can then add
ProxyPass /gitlab http://127.0.0.1:9242
ProxyPassReverse /gitlab http://127.0.0.1:9242
Restart Apache and GitLab, and it should work.