2019-05-23 20:48:08 -04:00
---
2020-09-28 08:10:02 -04:00
stage: Enablement
group: Distribution
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#designated-technical-writers
2019-05-23 20:48:08 -04:00
type: reference
---
2017-11-01 11:56:40 -04:00
# Install GitLab under a relative URL
2016-02-09 09:31:38 -05:00
2019-05-23 20:48:08 -04:00
While it is recommended to install GitLab on its own (sub)domain, sometimes
this is not possible due to a variety of reasons. In that case, GitLab can also
be installed under a relative URL, for example `https://example.com/gitlab` .
2016-02-09 09:31:38 -05:00
This document describes how to run GitLab under a relative URL for installations
from source. If you are using an Omnibus package,
2020-04-21 11:21:10 -04:00
[the steps are different ](https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-a-relative-url-for-gitlab ). Use this guide along with the
2016-02-09 09:31:38 -05:00
[installation guide ](installation.md ) if you are installing GitLab for the
2017-11-01 11:56:40 -04:00
first time.
2016-02-09 09:31:38 -05:00
2016-02-10 05:43:19 -05:00
There is no limit to how deeply nested the relative URL can be. For example you
could serve GitLab under `/foo/bar/gitlab/git` without any issues.
2016-02-09 09:31:38 -05:00
Note that by changing the URL on an existing GitLab installation, all remote
2016-02-10 05:43:19 -05:00
URLs will change, so you'll have to manually edit them in any local repository
2016-02-09 09:31:38 -05:00
that points to your GitLab instance.
The TL;DR list of configuration files that you need to change in order to
serve GitLab under a relative URL is:
2016-02-25 16:56:54 -05:00
- `/home/git/gitlab/config/initializers/relative_url.rb`
2016-02-09 09:31:38 -05:00
- `/home/git/gitlab/config/gitlab.yml`
- `/home/git/gitlab/config/unicorn.rb`
- `/home/git/gitlab-shell/config.yml`
- `/etc/default/gitlab`
2020-04-21 11:21:10 -04:00
After all the changes you need to recompile the assets and [restart GitLab ](../administration/restart_gitlab.md#installations-from-source ).
2016-02-09 09:31:38 -05:00
2017-11-01 11:56:40 -04:00
## Relative URL requirements
2016-02-09 09:31:38 -05:00
If you configure GitLab with a relative URL, the assets (JavaScript, CSS, fonts,
images, etc.) will need to be recompiled, which is a task which consumes a lot
of CPU and memory resources. To avoid out-of-memory errors, you should have at
least 2GB of RAM available on your system, while we recommend 4GB RAM, and 4 or
8 CPU cores.
See the [requirements ](requirements.md ) document for more information.
2017-11-01 11:56:40 -04:00
## Enable relative URL in GitLab
2016-02-09 09:31:38 -05:00
2017-11-01 11:56:40 -04:00
NOTE: **Note:**
2016-02-09 09:31:38 -05:00
Do not make any changes to your web server configuration file regarding
2017-11-01 11:56:40 -04:00
relative URL. The relative URL support is implemented by GitLab Workhorse.
2016-02-09 09:31:38 -05:00
---
Before following the steps below to enable relative URL in GitLab, some
assumptions are made:
- GitLab is served under `/gitlab`
- The directory under which GitLab is installed is `/home/git/`
Make sure to follow all steps below:
2019-07-11 11:21:26 -04:00
1. (Optional) If you run short on resources, you can temporarily free up some
memory by shutting down the GitLab service with the following command:
2016-02-09 09:31:38 -05:00
2019-07-11 11:21:26 -04:00
```shell
sudo service gitlab stop
```
2016-02-09 09:31:38 -05:00
2019-07-11 11:21:26 -04:00
1. Create `/home/git/gitlab/config/initializers/relative_url.rb`
2016-02-25 16:56:54 -05:00
2019-07-11 11:21:26 -04:00
```shell
cp /home/git/gitlab/config/initializers/relative_url.rb.sample \
/home/git/gitlab/config/initializers/relative_url.rb
```
2016-02-25 16:56:54 -05:00
2019-07-11 11:21:26 -04:00
and change the following line:
2016-02-09 09:31:38 -05:00
2019-07-11 11:21:26 -04:00
```ruby
config.relative_url_root = "/gitlab"
```
2016-02-09 09:31:38 -05:00
2019-07-11 11:21:26 -04:00
1. Edit `/home/git/gitlab/config/gitlab.yml` and uncomment/change the
following line:
2016-02-09 09:31:38 -05:00
2019-07-11 11:21:26 -04:00
```yaml
relative_url_root: /gitlab
```
2016-02-09 09:31:38 -05:00
2019-07-11 11:21:26 -04:00
1. Edit `/home/git/gitlab/config/unicorn.rb` and uncomment/change the
following line:
2016-02-09 09:31:38 -05:00
2019-07-11 11:21:26 -04:00
```ruby
ENV['RAILS_RELATIVE_URL_ROOT'] = "/gitlab"
```
2016-02-09 09:31:38 -05:00
2019-07-11 11:21:26 -04:00
1. Edit `/home/git/gitlab-shell/config.yml` and append the relative path to
the following line:
2016-02-09 09:31:38 -05:00
2019-07-11 11:21:26 -04:00
```yaml
gitlab_url: http://127.0.0.1/gitlab
```
2016-02-09 09:31:38 -05:00
2019-07-11 11:21:26 -04:00
1. Make sure you have copied the supplied init script and the defaults file
as stated in the [installation guide ](installation.md#install-init-script ).
Then, edit `/etc/default/gitlab` and set in `gitlab_workhorse_options` the
`-authBackend` setting to read like:
2016-02-09 09:31:38 -05:00
2019-07-11 11:21:26 -04:00
```shell
-authBackend http://127.0.0.1:8080/gitlab
```
2016-02-09 09:31:38 -05:00
2020-07-20 20:09:37 -04:00
NOTE: **Note:**
2019-07-11 11:21:26 -04:00
If you are using a custom init script, make sure to edit the above
2019-08-27 04:44:07 -04:00
GitLab Workhorse setting as needed.
2016-02-09 10:04:41 -05:00
2020-04-21 11:21:10 -04:00
1. [Restart GitLab ](../administration/restart_gitlab.md#installations-from-source ) for the changes to take effect.
2016-02-09 09:31:38 -05:00
2017-11-01 11:56:40 -04:00
## Disable relative URL in GitLab
2016-02-09 09:31:38 -05:00
2016-02-25 16:56:54 -05:00
To disable the relative URL:
2019-07-11 11:21:26 -04:00
1. Remove `/home/git/gitlab/config/initializers/relative_url.rb`
2016-02-25 16:56:54 -05:00
2019-07-11 11:21:26 -04:00
1. Follow the same as above starting from 2. and set up the
2016-02-25 16:56:54 -05:00
GitLab URL to one that doesn't contain a relative path.
2016-02-09 09:31:38 -05:00
2019-05-23 20:48:08 -04:00
<!-- ## Troubleshooting
Include any troubleshooting steps that you can foresee. If you know beforehand what issues
one might have when setting this up, or when something is changed, or on upgrading, it's
important to describe those, too. Think of things that may go wrong and include them here.
This is important to minimize requests for support, and to avoid doc comments with
questions that you know someone might ask.
Each scenario can be a third-level heading, e.g. `### Getting error message X` .
If you have none to add when creating a doc, leave this section in place
but commented out to help encourage others to add to it in the future. -->