Pre-existing nginx configuration issues

So I’ve just managed to install git lab on my server. On my server I currently run my own website, and so I have some nginx configuration stored on there (I’ve just added a couple files to /etc/nginx/sites-available and then symlinked them to .../sites-enabled.

Initially when I visited gitlab.mysite.com It sent me the welcome to nginx page, and I was a little confused by that, I did some searching online and found this article, which pretty much restarts gitlab, nginx and the server, but only starts gitlab back up (nginx not running). After following this, I managed to get onto gitlab, make the root user and get some configuration done.

My issue now is that when I try to start nginx I get the following errors:

user@myserver:~# journalctl -xe
Jul 10 19:43:27 myserver nginx[11067]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jul 10 19:43:27 myserver nginx[11067]: nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
Jul 10 19:43:27 myserver nginx[11067]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jul 10 19:43:28 myserver nginx[11067]: nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
Jul 10 19:43:28 myserver nginx[11067]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jul 10 19:43:28 myserver nginx[11067]: nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
Jul 10 19:43:28 myserver nginx[11067]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jul 10 19:43:29 myserver nginx[11067]: nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
Jul 10 19:43:29 myserver nginx[11067]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jul 10 19:43:29 myserver nginx[11067]: nginx: [emerg] still could not bind()
Jul 10 19:43:29 myserver systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
-- Subject: Unit process exited
-- Defined-By: systemd
-- Support: https://www.debian.org/support
-- 
-- An ExecStart= process belonging to unit nginx.service has exited.
-- 
-- The process' exit code is 'exited' and its exit status is 1.
Jul 10 19:43:29 myserver systemd[1]: nginx.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
-- 
-- The unit nginx.service has entered the 'failed' state with result 'exit-code'.
Jul 10 19:43:29 myserver systemd[1]: Failed to start A high performance web server and a reverse proxy server.
-- Subject: A start job for unit nginx.service has failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support

I’m not too familiar with nginx, but my intuition tells me that there’s probably some conflict with my nginx configuration and what gitlab is trying to do.

If anyone has experience hosting gitlab on their own server, while hosting websites and has some ideas, please let me know. Thanks in advance.

Ok, so I managed to figure out one method to do this. Based on this post, it seems like it’s a better idea to make sure that gitlab has a blank canvas, so having a site running on nginx could cause some conflicts.

After a quick discussion on the #networking channel on IRC there seem to be two options:

  1. Either configure that to run on a different port say 81 or whatever floats your boat
  2. enable a reverse proxy so a specific path goes to your gitlab server
    for example: example.com/* goes to your regular webserver while example.com/gitlab/* will reverse proxy into localhost:81 (lets say gitlab is configured to listen at localhost:81 instead of *:81)

For simplicity I went with option 1, namely editing /etc/gitlab/gitlab.rb file to be external_url "https://mysite.com:81" and then reconfigured, restarted gitlab, and then tried starting nginx once more failed because it kept saying that port 80 was in use alread (which didn’t make sense since I just specified it to be port 81).

Though this post revelead the fix, namely removing the old syntax from all of my sites server blocks (had to do each each nginx site config I made). Then restarting nginx one last time works.
And I can run my site as well as gitlab on the same server.

2 Likes

Thank you so much for sharing all this @cuppajoeman! It’s super helpful when users follow up and let us know what worked for them! :blush: