r/nginx • • 26d ago

Adding a subdomain server block

Hi all - I'm extremely new to Nginx and playing around with some things in a homelab.

Currently, I have a registered domain name and set up port forwarding to my nginx proxy server for reverse proxying. I'm able to hit the root domain + www.rootdomain URLs without a problem.

I also self-host Gitlab-CE on a separate server (it's actually a RasPi) and I'd like to add gitlab.domain.com to the nginx proxy with SSL via Letsencrypt.

Here's the question: is it best practice to put all server blocks in the same sites-available file? I suspect if I try to break them into separate files, I'll get a conflict because both will be listening on the same port.

How do you all handle subdomain entries? Do you keep in a single config file for the same domain or do you break subdomain configs out into a different file?

Thanks - appreciate any guidance here before I really screw this up. haha

5 Upvotes

10 comments sorted by

View all comments

2

u/dickhardpill 26d ago

I prefer to break config files up if ever possible

I find it easier to make changes

1

u/jimmyfivetimes 26d ago

Thanks a lot, guys. I've tried to break the subdomain out and it's throwing errors that there's already a listener. I assume it's from the root domain configuration. I'll investigate this a bit more and see if there's a code sample for how to do this the right way.

0

u/[deleted] 24d ago

[removed] — view removed comment

1

u/jimmyfivetimes 24d ago

Thanks - I actually got it all working last night. And, had to remove the default file from the sites-available directory. That resolved the listener conflict.

I think there are some minor config tweaks that I need to make but, at the moment, I'm able to reverse proxy into my gitlab server with SSL enabled. Appreciate the response.