October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Set Up Separate NGINX Config Files for Multiple Sites

Create one NGINX server block per site, load the files with the correct include, enable them using symlinks or conf.d, then validate and reload safely.
Length10 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Put each website in its own server { ... } file, make sure the main NGINX configuration includes that file, give the site a matching server_name, test the complete configuration, and reload NGINX. Ubuntu and Debian packages normally use /etc/nginx/sites-available/ plus symlinks in /etc/nginx/sites-enabled/. Other installations commonly load *.conf files from /etc/nginx/conf.d/. The split is organizational; a file has no effect until the active nginx.conf includes it.

How separate NGINX files fit together

NGINX serves multiple websites through virtual hosting. For HTTP traffic, one or more server blocks live inside the http { } context. Each block describes a site’s listening address and port, host names, document root, indexes, and URI handling. A location { } block belongs inside a server block and controls requests for matching paths.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The main configuration file is usually called nginx.conf. It is the configuration NGINX starts with; separate files are read only through an include directive in that file or in a file that it includes. Consequently, creating a file in a familiar directory does not automatically enable it. Always verify the include path used by the running installation.

Splitting sites has practical advantages:

  • One site can be edited without searching through a large monolithic file.
  • A site can be enabled or disabled independently.
  • Configuration changes are easier to review and back up by site.
  • Syntax errors can be associated with the file that introduced them.

Separate files do not create isolation. NGINX still merges them into one effective configuration, so duplicate names, conflicting listeners, and an unexpected default server can affect more than one site.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

Choose the layout used by your installation

Layout Source-file directory How a site is enabled Typical advantage How to disable one site
Ubuntu/Debian package convention /etc/nginx/sites-available/ Create a symlink in /etc/nginx/sites-enabled/ Matches the documented multi-site workflow on these distributions Remove the individual symlink while retaining the source file
Include-based layout /etc/nginx/conf.d/ Place a matching file such as example.test.conf where an include loads it Portable across installations that use the upstream-style directory Move the file out of the included directory or change its extension so the pattern no longer matches

Ubuntu’s server documentation describes sites-available and sites-enabled for multiple websites. Debian documents the enabled entries as symlinks to files in sites-available, while treating conf.d/*.conf as an additional configuration directory. F5 NGINX documentation describes splitting feature-specific configuration into /etc/nginx/conf.d and loading it from the main file.

Do not assume that a distribution’s directory exists or is active. A custom build, container image, or vendor package may use a different prefix and include pattern.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Identify the active configuration before editing

First find the binary’s compiled paths and then inspect the configuration it actually reads.

  1. Run
    nginx -V

    Look for the configured prefix and the path supplied for the main configuration file. Use sudo if the binary or its directories are restricted.

  2. Open the reported nginx.conf and locate the http { } section. Search for lines such as include /etc/nginx/sites-enabled/*; or include /etc/nginx/conf.d/*.conf;.
  3. Confirm that the include appears inside http { } when it loads HTTP server blocks. An include placed only in events { }, or outside the proper context, cannot load an HTTP server block correctly.
  4. Record the exact pattern. A file named example.test is loaded by a wildcard such as sites-enabled/*, but not by conf.d/*.conf unless its name ends in .conf.

When the configuration path is uncertain, sudo nginx -T prints the tested, merged configuration. The output includes files pulled in by include directives and is useful for confirming that a new site is really part of the running configuration.

Set up a site on Ubuntu or Debian

The following example creates a static site named example.test. Replace the domain and paths with values for your own site. The example assumes the package has an active sites-enabled/* include.

1. Create the document root

sudo mkdir -p /srv/example.test/html
sudo sh -c 'printf "%sn" "Example site" > /srv/example.test/html/index.html'

The directory is only an example; choose a location appropriate for your deployment. Put the site’s actual files in this document root and ensure the NGINX worker can read them. The configuration below does not grant write access or create application users.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed

2. Write one complete server block

Create /etc/nginx/sites-available/example.test:

server {
    listen 80;
    listen [::]:80;
    server_name example.test www.example.test;

    root /srv/example.test/html;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

This block listens on IPv4 and IPv6 port 80, accepts requests whose host header is example.test or www.example.test, serves files below the declared root, and uses index.html for directory requests. try_files checks the requested path and returns HTTP 404 when neither a file nor a directory exists.

Keep the block self-contained: a site file should include the directives needed by that site rather than relying on an accidental order in another site’s file. Shared settings can be factored into a separate included file later, but test the merged result after every change.

3. Enable the site with a symlink

sudo ln -s /etc/nginx/sites-available/example.test 
  /etc/nginx/sites-enabled/example.test

The source remains in sites-available; the symlink is the enablement switch. If the link already exists, inspect it before replacing it so you do not hide a different configuration.

4. Decide what to do with the packaged default site

Many Ubuntu and Debian installations enable a default server. If its behavior is not wanted, inspect it and remove only its enablement symlink:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo rm /etc/nginx/sites-enabled/default

Removing the symlink does not delete the source file in sites-available. Check the consequences first: the default may currently provide a diagnostic page, a catch-all response, or another service you still need. You can restore it by recreating the appropriate symlink.

5. Test the complete configuration

sudo nginx -t

A successful test reports that the syntax is valid and that the configuration test is successful. A failure identifies a file and line number; fix that error before attempting a reload. Testing is important because NGINX evaluates the merged configuration, not just the file you edited.

Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

6. Reload without stopping NGINX

sudo systemctl reload nginx

A reload asks the running service to apply the validated configuration while existing workers finish current requests. If the service manager reports a failure, inspect its status and logs rather than repeatedly reloading an unverified file.

Set up a site with conf.d

Use this procedure when the active nginx.conf contains an include such as:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
http {
    include /etc/nginx/conf.d/*.conf;
}

The include must be in the HTTP context for HTTP server blocks. Do not add a second include merely because the directory exists; duplicate or overlapping patterns can load the same file twice.

1. Create a file that matches the include pattern

sudo editor /etc/nginx/conf.d/example.test.conf

Put the same complete server block in that file:

server {
    listen 80;
    listen [::]:80;
    server_name example.test www.example.test;

    root /srv/example.test/html;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

The .conf suffix matters when the include uses *.conf. A file with another suffix will remain on disk but will not be read by that pattern.

2. Test and reload

sudo nginx -t
sudo systemctl reload nginx

Use the same test-before-reload discipline as with the Debian-style layout. To disable this site later, remove or rename the matching file, run nginx -t, and reload only after the test succeeds. Keep a copy in a separate configuration directory or version-control system if you need an easy rollback.

Give every site a distinct identity

server_name must match the request

NGINX uses the requested host name, supplied in the HTTP Host header, to choose among server blocks that share an address and port. Include every name the site should answer for, such as the bare domain and its www form. A typo, missing alias, or request made directly to an IP address can send traffic to another server block.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC

DNS is a separate requirement. The domain’s records must point to the machine running NGINX; a perfectly valid server block cannot receive a request that resolves elsewhere. Test with the real host name and, where appropriate, an explicit request to the server’s address while supplying the intended host header.

Choose compatible listen settings

Each server block needs listening settings appropriate to the traffic it handles. The example uses port 80 on both IPv4 and IPv6. Several domains can share port 80 or 443 when their server_name values distinguish them, but two blocks cannot both claim the same address and port as an unconditional default without creating a conflict. Follow the complete syntax supported by the installed package and verify it with nginx -t.

Ubuntu’s documented introductory example calls for a unique server_name and a different listen port number for each site. That wording describes its example arrangement; real name-based hosting commonly places multiple domains on the same web port. The deciding factors are the actual listen directives, name matching, and whether one block is marked default_server.

Understand default servers and ordering

If no server block matches the requested name, NGINX sends the request to the default server for that listening address and port. An explicitly marked default_server takes that role; otherwise, NGINX uses the first suitable server for the address and port in the effective configuration order.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

This explains a common symptom: nginx -t passes, but a browser shows the distribution’s welcome page. The new file may be loaded correctly while the request’s host name does not match, DNS may point to another machine, or the old default site may still be enabled. Use sudo nginx -T to see the merged order, the active default, and every loaded server_name.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Validate changes safely

  • Test after every edit: Run sudo nginx -t before any reload.
  • Inspect the merged view: Run sudo nginx -T when diagnosing includes, ordering, duplicate definitions, or an unexpected default.
  • Reload only a passing configuration: Use sudo systemctl reload nginx after a successful test.
  • Keep the last known-good file: A version-control commit or dated backup makes rollback straightforward.
  • Check service output: If a reload fails, inspect service status and NGINX error logs for the exact file and line involved.

Syntax validation checks whether NGINX can parse and assemble the configuration. It does not prove that DNS is correct, files exist under the document root, permissions allow reads, or the intended host name reaches this server. Those operational checks must follow a successful configuration test.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

Troubleshoot the most common failures

The new site is ignored completely

  • Confirm the file is in a directory covered by an active include.
  • Check the filename against the wildcard. For conf.d/*.conf, use a .conf suffix.
  • Run sudo nginx -T and search its output for the file’s distinctive server_name.
  • Verify that the include is inside http { } for an HTTP server block.

NGINX refuses to reload

  • Run sudo nginx -t and correct the reported line first.
  • Check braces, semicolons, directive spelling, and file paths.
  • Look for a duplicate or conflicting listen declaration introduced by another enabled file.
  • Do not delete unrelated files to make the error disappear; identify which include created the conflict.

The wrong site answers

  • Confirm the browser’s host name exactly matches a server_name in the intended block.
  • Check DNS records and IPv4 versus IPv6 resolution.
  • Inspect default_server declarations and the effective order with nginx -T.
  • Remove an unwanted default-site symlink only after checking what it currently serves.

The site returns 404 for an existing-looking URL

  • Verify that root points to the directory containing the requested file.
  • Check the path and filename, including case on case-sensitive filesystems.
  • Review the try_files behavior. The sample intentionally returns 404 when neither a file nor a directory matches.
  • Inspect the NGINX error log after confirming the request reached the intended server block.

The test passes but requests still fail

A passing syntax test means only that NGINX accepted the configuration. Confirm that the service actually reloaded, that DNS reaches this host, that the document root contains the content, and that the worker process can read it. Service status and error logs distinguish a routing problem from a filesystem or deployment problem.

Organize additional sites consistently

For a second site, repeat the same pattern with a different filename, document root, server_name, and any site-specific locations. On Ubuntu or Debian, create its source file in sites-available and a corresponding symlink in sites-enabled. On an include-based installation, create another matching file in conf.d. Avoid editing the central nginx.conf for every new domain; edit it only when the include policy itself needs to change.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use descriptive names that make the relationship obvious, such as example.test or example.test.conf. Keep one logical site per file unless two blocks are intentionally coupled, for example a separate HTTP and HTTPS block for the same domain. Document which names and ports each file owns so a future change does not accidentally overlap another site.

Before removing a site, disable its symlink or move its included file, test the resulting configuration, and reload. Retaining the source file makes temporary maintenance, rollback, and later re-enablement safer than deleting the configuration outright.

A repeatable workflow for every new domain

  1. Confirm the active main configuration path with nginx -V.
  2. Locate the include that loads site files and identify its required directory and filename pattern.
  3. Create the document root and deploy the site content.
  4. Write one complete server block with the intended listen, server_name, root, and location directives.
  5. Enable it with a symlink or by placing the file where the include pattern matches.
  6. Run sudo nginx -t.
  7. Use sudo nginx -T if you need to verify inclusion, ordering, or default-server behavior.
  8. Reload with sudo systemctl reload nginx.
  9. Test the real domain, then check logs if the response does not come from the intended block.

This workflow keeps site-specific work in separate files while preserving one authoritative validation point: the fully merged NGINX configuration that the service will actually load.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.