skip to Main Content

I installed gitlab according to the official documentation.

sudo docker run --detach 
  --hostname git.stupidpz.com 
  --publish 8443:443 --publish 880:80 --publish 822:22 
  --name gitlab 
  --restart always 
  --volume $GITLAB_HOME/config:/etc/gitlab 
  --volume $GITLAB_HOME/logs:/var/log/gitlab 
  --volume $GITLAB_HOME/data:/var/opt/gitlab 
  --shm-size 256m 
  gitlab/gitlab-ee:latest

Now I want to use Nginx(installed By Myself) to reverse proxy gitlab instead of the nginx that comes with the gitlab container.

According to official documentation I added some code in gitlab.rb

# Define the external url
external_url 'http://git.stupidpz.com'

# Disable the built-in nginx
nginx['enable'] = false

# Disable the built-in puma
puma['enable'] = false

# Set the internal API URL
gitlab_rails['internal_api_url'] = 'http://git.stupidpz.com'

# Define the web server process user (ubuntu/nginx)
web_server['external_users'] = ['nginx']

Then gitlab cannot be accessed, I found some error logs in this file /var/log/gitblab/gitlab_workhorse/current

{"correlation_id":"","duration_ms":0,"error":"badgateway: failed to receive response: dial tcp 127.0.0.1:8080: connect: connection refused","level":"error","method":"GET","msg":"","time":"2023-01-25T20:57:21Z","uri":""}
{"correlation_id":"","duration_ms":0,"error":"badgateway: failed to receive response: dial tcp 127.0.0.1:8080: connect: connection refused","level":"error","method":"GET","msg":"","time":"2023-01-25T20:57:31Z","uri":""}
{"correlation_id":"","duration_ms":0,"error":"badgateway: failed to receive response: dial tcp 127.0.0.1:8080: connect: connection refused","level":"error","method":"GET","msg":"","time":"2023-01-25T20:57:41Z","uri":""}
{"correlation_id":"","duration_ms":0,"error":"badgateway: failed to receive response: dial tcp 127.0.0.1:8080: connect: connection refused","level":"error","method":"GET","msg":"","time":"2023-01-25T20:57:51Z","uri":""}

Did nothing else except for adding some code in gitlab.rb.

I wonder where this dial tcp 127.0.0.1:8080 comes from?

I hope you can help me, or give me a correct demo.Many thanks.This problem has been bothering me for two days

2

Answers


  1. Chosen as BEST ANSWER

    Now i figure out why i could not make it works,I mixed up Using an existing Passenger/NGINX installation and Using a non-bundled web-server If you just need to use your own nginx to proxy gitlab(both of them was installed on docker) you just need to add two lines to gitlab.rb.

    # Disable the built-in nginx
    nginx['enable'] = false
    # Define the web server process user (ubuntu/nginx)
    web_server['external_users'] = ['nginx']
    

    and here is nginx's conf

    upstream gitlab-workhorse {
      server unix://var/opt/gitlab/gitlab-workhorse/sockets/socket fail_timeout=0;
    }
    
    server {
      listen *:80;
      server_name git.example.com;
      server_tokens off;
      root /opt/gitlab/embedded/service/gitlab-rails/public;
    
      client_max_body_size 250m;
    
      access_log  /var/log/gitlab/nginx/gitlab_access.log;
      error_log   /var/log/gitlab/nginx/gitlab_error.log;
    
      # Ensure Passenger uses the bundled Ruby version
      passenger_ruby /opt/gitlab/embedded/bin/ruby;
    
      # Correct the $PATH variable to included packaged executables
      passenger_env_var PATH "/opt/gitlab/bin:/opt/gitlab/embedded/bin:/usr/local/bin:/usr/bin:/bin";
    
      # Make sure Passenger runs as the correct user and group to
      # prevent permission issues
      passenger_user git;
      passenger_group git;
    
      # Enable Passenger & keep at least one instance running at all times
      passenger_enabled on;
      passenger_min_instances 1;
    
      location ~ ^/[w.-]+/[w.-]+/(info/refs|git-upload-pack|git-receive-pack)$ {
        # 'Error' 418 is a hack to re-use the @gitlab-workhorse block
        error_page 418 = @gitlab-workhorse;
        return 418;
      }
    
      location ~ ^/[w.-]+/[w.-]+/repository/archive {
        # 'Error' 418 is a hack to re-use the @gitlab-workhorse block
        error_page 418 = @gitlab-workhorse;
        return 418;
      }
    
      location ~ ^/api/v3/projects/.*/repository/archive {
        # 'Error' 418 is a hack to re-use the @gitlab-workhorse block
        error_page 418 = @gitlab-workhorse;
        return 418;
      }
    
      # Build artifacts should be submitted to this location
      location ~ ^/[w.-]+/[w.-]+/builds/download {
          client_max_body_size 0;
          # 'Error' 418 is a hack to re-use the @gitlab-workhorse block
          error_page 418 = @gitlab-workhorse;
          return 418;
      }
    
      # Build artifacts should be submitted to this location
      location ~ /ci/api/v1/builds/[0-9]+/artifacts {
          client_max_body_size 0;
          # 'Error' 418 is a hack to re-use the @gitlab-workhorse block
          error_page 418 = @gitlab-workhorse;
          return 418;
      }
    
      # Build artifacts should be submitted to this location
      location ~ /api/v4/jobs/[0-9]+/artifacts {
          client_max_body_size 0;
          # 'Error' 418 is a hack to re-use the @gitlab-workhorse block
          error_page 418 = @gitlab-workhorse;
          return 418;
      }
    
    
      # For protocol upgrades from HTTP/1.0 to HTTP/1.1 we need to provide Host header if its missing
      if ($http_host = "") {
      # use one of values defined in server_name
        set $http_host_with_default "git.example.com";
      }
    
      if ($http_host != "") {
        set $http_host_with_default $http_host;
      }
    
      location @gitlab-workhorse {
    
        ## https://github.com/gitlabhq/gitlabhq/issues/694
        ## Some requests take more than 30 seconds.
        proxy_read_timeout      3600;
        proxy_connect_timeout   300;
        proxy_redirect          off;
    
        # Do not buffer Git HTTP responses
        proxy_buffering off;
    
        proxy_set_header    Host                $http_host_with_default;
        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://gitlab-workhorse;
    
        ## The following settings only work with NGINX 1.7.11 or newer
        #
        ## Pass chunked request bodies to gitlab-workhorse as-is
        # proxy_request_buffering off;
        # proxy_http_version 1.1;
      }
    
      ## Enable gzip compression as per rails guide:
      ## http://guides.rubyonrails.org/asset_pipeline.html#gzip-compression
      ## WARNING: If you are using relative urls remove the block below
      ## See config/application.rb under "Relative url support" for the list of
      ## other files that need to be changed for relative url support
      location ~ ^/(assets)/ {
        root /opt/gitlab/embedded/service/gitlab-rails/public;
        gzip_static on; # to serve pre-gzipped version
        expires max;
        add_header Cache-Control public;
      }
    
      ## To access Grafana
      location /-/grafana/ {
        proxy_pass http://localhost:3000/;
      }
    
      error_page 502 /502.html;
    }
    

    last but not least,you need to add another bash to your nginx's container,

    -v /var/opt/gitlab:/var/opt/gitlab
    

    This will let your nginx container connect to gitlab container.Otherwise you will get "cannot find var/opt/gitlab/gitlab-workhorse/sockets/socket".


  2. It looks like you are installing a GitLab instance as a custom git server on a remote host. There are 3 pieces of this that must work.

    1. DNS setup, remote host’s ports and firewall setup.
    2. Working installation of GitLab on the remote host.
    3. Valid SSL certificates, and a correct nginx config for HTTPS.

    The first step really depends on your virtual machine and container’s setup, but essentially, make sure it (the VM or container) has a public port that responds to requests.

    These variables must be set in the remote host’s environment as such

    –volume $GITLAB_HOME/config:/etc/gitlab
    –volume $GITLAB_HOME/logs:/var/log/gitlab
    –volume $GITLAB_HOME/data:/var/opt/gitlab

    The above URL covers all the GitLab install steps once you have signed in and verified that it was installed correctly and that it runs as expected on that remote host.

    Only then, install and configure nginx. Since GitLab likely will transfer credentials and other secure data, you will need to setup https on nginx.

    An example of an Nginx configuration can be found here. There is also a tool by Mozilla that makes building a custom nginx config easier, found here.

    The error you show has this URL "127.0.0.1:8080". It is likely you have supplied this URL to the gitlab.rb config somewhere, and that might be a mistake. I cannot be sure without the whole config file however.

    Also, it is likely the GitLab image will need to run its own nginx instance, so that the said container when launched may do its job and act as a git server. To reverse proxy this GitLab instance, you may need to install nginx onto your host machine and point it to GitLab Image’s nginx.

    You may be able to do away with the second nginx instance by appending a new server {} block into the Gitlab Image’s nginx config. I would not recommend this.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search