Gitlab keeps using port 80

Hello,
I need some help with setting up a Gitlab server. I have an Nginx server installed, where I host some stuff, and a GitLab server. I configured Gitlab so, that it should use port 8081, but it keeps blocking port 80, which then prevents my Nginx installation from binding to port 80.
I’m already desperate and have no idea what the problem could be (I also didn’t set up SSL for now, since so little was working that I wanted to get it running without it first so I could rule out potential sources of error).

Content of various config files:

/etc/gitlab/gitlab.rb

nginx['listen_addresses'] = ['127.0.0.1']
nginx['listen_port'] = 8081
external_url 'http://gitlab.example.org:8081'
  • /etc/nginx/sites-enabled/...
  • default
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;

        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                try_files $uri $uri/ =404;
        }
}
server {
      listen 80;
      listen [::]:80;

      server_name example.com;

      root /var/www/html;
      index example.index.html;

      location / {
            try_files $uri $uri/ =404;
      }
}
server {
      listen 80;
      listen [::]:80;

      server_name foo.example.com;

      root some/path/;
      # index index.html;

      location / {
            autoindex on;
            try_files $uri $uri/ =404;
            auth_basic "Restricted Content";
            auth_basic_user_file /etc/nginx/.htpasswd;
      }
}
server {
    listen 80;
    listen [::]:80;

    server_name gitlab.example.com;

    location / {
        proxy_pass http://localhost:8081;
        proxy_redirect off;
        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_set_header X-Forwarded-Protocol $scheme;
        proxy_set_header X-Url-Scheme $scheme;
    }

    access_log /var/log/nginx/gitlab_access.log;
    error_log /var/log/nginx/gitlab_error.log;
}

I ran sudo gitlab-ctl reconfigure and sudo gitlab-ctl restart

Output of systemctl status nginx.service:

● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Mon 2022-04-04 23:01:50 UTC; 4s ago
       Docs: man:nginx(8)
    Process: 75394 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 75406 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)

Apr 04 23:01:48 brick systemd[1]: Starting A high performance web server and a reverse proxy server...
Apr 04 23:01:48 brick nginx[75406]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 04 23:01:48 brick nginx[75406]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 04 23:01:49 brick nginx[75406]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 04 23:01:49 brick nginx[75406]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 04 23:01:50 brick nginx[75406]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 04 23:01:50 brick nginx[75406]: nginx: [emerg] still could not bind()
Apr 04 23:01:50 brick systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Apr 04 23:01:50 brick systemd[1]: nginx.service: Failed with result 'exit-code'.
Apr 04 23:01:50 brick systemd[1]: Failed to start A high performance web server and a reverse proxy server.

(PS: Nginx is startet after GitLab)

— I hope you can help me and tell my why GitLab still blocks port 80.

Hi,

According to the documentation: NGINX settings | GitLab

point 1 says you need to disable the bundled nginx, so:

nginx['enable'] = false

This indeed fixed my issue with with the address beeing blocked, but not i allways get an 502 bad gateway error. Do you can help me?
Running curl http://127.0.0.1:8081 results in
curl: (7) Failed to connect to 127.0.0.1 port 8081: Connection refused

That sounds like you haven’t configured your own nginx (the one you wanted to listen to port 80) to forward relevant requests correctly. That doesn’t have anything to do with GitLab and as such falls outside the scope of this forum.

Thanks for all the response, but I gave up on this topic and just used a docker container.