Ehsan Iran-Nejad
Ehsan Iran-Nejad

Reputation: 1817

gitlab docker nginx reverse proxy to a sub path

I'm trying to setup nginx as a reverse proxy to route apps.mycompany.com/gitlab to a gitlab docker container running on the same server as nginx:

nginx config has:

location /gitlab/ {
    proxy_pass     http://127.0.0.1:3000/;
    proxy_redirect default;
}

the first http call apps.mycompany.com/gitlab goes smoothly but basically all the hrefs inside the html (e.g. href:"/assets/...") are still routing to apps.mycompany.com/assets/... instead of apps.mycompany.com/gitlab/assets/...

So no assets and css files are found. The rendered page has structure but no styling and I don't even know what else doesn't work.

I don't know nginx enough to know what I'm doing wrong

Upvotes: 3

Views: 3841

Answers (2)

Zhang Buzz
Zhang Buzz

Reputation: 11068

My gitlab setting for https:

docker-compose.yml:

web:
  image: 'gitlab/gitlab-ee:latest'
  restart: always
  hostname: 'gitlab.yourdomain.com'
  environment:
    GITLAB_OMNIBUS_CONFIG: |
      external_url 'https://gitlab.yourdomain.com'
      gitlab_rails['gitlab_shell_ssh_port'] = 9122
      nginx['enable'] = true
      nginx['listen_port'] = 9180
      nginx['listen_https'] = false
  ports:
    - '9180:9180'
    - '9122:22'
  volumes:
    - '/opt/gitlab/config:/etc/gitlab'
    - '/opt/gitlab/logs:/var/log/gitlab'
    - '/opt/gitlab/data:/var/opt/gitlab'

nginx gitlab.conf:

server {
  listen       443;
  server_name  gitlab.yourdomain.com;

  location / {
    proxy_set_header    Host                $http_host;
    proxy_set_header    X-Real-IP           $remote_addr;
    proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
    proxy_set_header    X-Forwarded-Proto   $scheme;
    proxy_pass http://127.0.0.1:9180;
  }
}

Upvotes: 0

lmtx
lmtx

Reputation: 5586

NGINX

In your nginx configuration add proxy_set_header option and change proxy_pass like following:

location /gitlab/ {
    proxy_set_header Host $http_host;
    proxy_pass http://127.0.0.1:3000/gitlab/;
}

GITLAB

What you are looking for is relative URL configuration in GitLab.

If you have GitLab in version 8.5 or above do one of following depending on your GitLab deployment type:

DOCKER-COMPOSE deployment

Add environment variable external_url to your docker-compose.yml file, sample file:

gitlab:
    image: 'gitlab/gitlab-ce:11.5.2-ce.0'
    restart: always
    environment:
            GITLAB_OMNIBUS_CONFIG: |
                    external_url 'http://apps.mycompany.com/gitlab/'
    ports:
            - '3000:80'

Then restart GitLab docker:

docker-compose up -d

DOCKER deployment

If you are not using docker-compose (which I strongly recommend) then you can add external_url option to you docker run command, sample execution:

docker run --detach --publish 3000:80 --restart always --env GITLAB_OMNIBUS_CONFIG="external_url 'http://apps.mycompany.com/gitlab/'" gitlab/gitlab-ce:11.5.2-ce.0

GitLab configuration files update - can be used in all kinds of deployments

Another approach is to directly modify the GitLab configuration file but I would recommend that for standalone GitLab installations not for docker deployments.

Modify GitLab configuration in /etc/gitlab/gitlab.rb change the external_url value to following:

external_url "http://apps.mycompany.com/gitlab"

Afther this change you have to reconfigure GitLab:

sudo gitlab-ctl reconfigure

Then restart service:

sudo gitlab-ctl restart

You can find more details about GitLab configuration in official documentation.

I recommend that you also check GitLab in docker deployment official documentation.

Please note that relative URL support in Omnibus GitLab is experimental and was introduced in version 8.5 (for earlier version you need to compile it from source - doc).

Upvotes: 7

Related Questions