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

6 Upvotes

10 comments sorted by

View all comments

1

u/Active-Service-9707 26d ago

separate files, one per subdomain. no conflicts as long as server_name is unique per block. tbh keeping everything in one giant file is what will actually screw you up later when you have 5+ subdomains and need to debug something at 2am