Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
FREEDOM251

Freedom251 › Blog › DNS

Nginx Server Blocks Not Working: A Step-by-Step Troubleshooting Guide

By Freedom251 Team · · 11 min read

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

If Nginx serves its welcome page, sends a different site, or routes HTTP and HTTPS inconsistently, the usual cause is that the request is not selecting the server block you edited. Nginx chooses a block by local IP address and port first, then by the request’s Host name. If no name matches, it uses the default server for that listening port.

Work from the outside in: test the configuration, inspect the complete loaded configuration, verify DNS and IPv4/IPv6, then check listen, server_name, TLS, and content directives. This order separates routing errors from document-root, proxy, permission, and application failures.

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.

How Nginx chooses a server block

Nginx does not select a virtual host merely because a configuration file exists on disk. For every connection it evaluates the address and port accepted by a listen directive. When multiple server blocks share that address and port, it compares the HTTP Host header with each block’s server_name.

Name matching has a defined priority:

  1. An exact name, such as www.example.com.
  2. The longest wildcard beginning with an asterisk, such as *.example.com.
  3. The longest wildcard ending with an asterisk, such as mail.*.
  4. The first matching regular expression name.

If none of the names matches, Nginx sends the request to the default server for that address and port. The default server is a property of the listening port, not of server_name. A block can therefore be syntactically valid yet never receive the request you are testing.

Start with a symptom-to-cause check

What you see Likely routing issue First check
Nginx welcome page or another site The request selected a different block or the default server. Run nginx -T; inspect listen, server_name, and any default_server.
HTTP works, but HTTPS opens the wrong site The 443 listener, TLS default, certificate, or IPv6 path differs from port 80. Inspect every listen 443 block and test TLS with the intended hostname.
The domain works on one network but not another Different DNS answers, often an IPv4/IPv6 mismatch. Check both address records and test each address family.
Editing a file has no effect The file is not included by the active configuration, or a different Nginx installation is running. Compare nginx -V with the filename shown by nginx -T.
The correct site is selected but content is wrong root, index, location, or proxy_pass points elsewhere. Inspect the selected block’s content directives after routing is confirmed.
Nginx will not reload after adding names The server-name hash cannot be built with current defaults. Read the exact startup error before changing hash settings.

1. Test syntax before reloading

Always validate the configuration and referenced files before a reload or restart:

sudo nginx -t

A successful test reports that the syntax is valid and the test is successful. If it fails, fix the file and line identified in the error before investigating request routing. Common blockers include a missing semicolon, an unmatched brace, a misspelled directive, a certificate file that does not exist, or an include path that cannot be read.

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

Do not use a restart as a diagnostic shortcut. A failed restart can take a working service down, while nginx -t lets you correct the configuration without replacing the running process.

2. Inspect the configuration Nginx actually loaded

The file you edited is not necessarily the file Nginx is using. Display the complete effective configuration with:

sudo nginx -T

Search that output for three things:

  • The intended filename or a distinctive comment from it.
  • Every listen line for the address and port you are testing.
  • Every relevant server_name, including www and wildcard variants.

If your block does not appear, follow the include directives from the active main configuration. The compiled configuration path is shown by:

nginx -V

Read the output carefully: the configure arguments identify the main configuration path and can reveal that a package, container, or custom build is using a different location than the one you edited. A typical mistake is changing a file in an “available” directory while no include reaches it, or creating a symlink that points to a filename excluded by the active configuration.

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

Confirm which process and installation you are testing

Run the commands with the same administrative context used to manage the service. On systems with multiple installations, the nginx binary in your shell may not be the binary launched by the service manager. Compare the executable and compiled path reported by nginx -V with the service definition and with the configuration dump. If they differ, make one installation authoritative before editing further.

Rank #2
40 Pcs/20 Set Rack Mount Screws and Cage Nuts for Server Rack Cabinet, Black Carbon Steel M6 x 20 mm Screws with Nylon Washers and Cage Nuts, Rack Mount Hardware for Server Racks/Shelves/Cabinets
  • Durable Carbon Steel: Rack mount screws and cage nuts are made of high-quality carbon steel with a black finish for high strength and dependable durability.
  • Easy Installation: Clear metric threads and uniform pitch for better grip. Nylon washers help secure screws and protect equipment surfaces.
  • Organized Storage: All parts are packed in a portable storage box for easy organization and access.
  • Wide Compatibility: Fits most square-hole racks and cabinets—ideal for server racks, network cabinets, equipment enclosures, and A/V gear.
  • 20-Set Kit: Includes 20 mounting screws with nylon washers (M6 x 20 mm) and 20 square cage nuts—40 pieces in total—meeting daily install and replacement needs.

3. Verify DNS reaches this machine

A perfect server block cannot answer a request that arrives at another address. Confirm that the hostname resolves to the machine you are testing. Check every published address record, not only the first IPv4 result. If the domain has both IPv4 and IPv6 records, a client may choose IPv6 while your block listens only on IPv4.

Compare the destination address with the machine’s public addresses. Test the two paths independently when both are published:

  • For IPv4, connect to the IPv4 address while preserving the intended hostname in the request.
  • For IPv6, connect to the IPv6 address while preserving the same hostname.

If one family reaches a different host, update DNS or configure Nginx on the missing address family. Do not diagnose server_name until the request is reaching the correct machine; Nginx cannot match a block on a server that never receives the connection.

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

Remember what an IP-address request sends

When you browse directly to an IP address, the HTTP Host header contains that IP. A block whose names contain only example.com will not match an IP-address request, so Nginx may intentionally select the default server. Test with the real hostname whenever you are checking name-based routing.

4. Audit every listen directive

The listening socket must match the connection exactly. Make the intended address and port explicit while troubleshooting. A basic HTTP block commonly contains:

listen 80;

An HTTPS block commonly contains:

listen 443 ssl;

Check for these failure modes:

  • The request uses port 80 but the block listens on another port.
  • The block listens on a specific address while the request arrives on a different local address.
  • Only an IPv4 listener exists even though DNS sends clients to IPv6.
  • HTTPS is configured on 443 but the tested service is terminating TLS elsewhere.
  • Several blocks claim the same address and port with an unintended default.

For each address and port combination, choose one deliberate default_server. If no block is marked explicitly, Nginx uses the first block loaded for that socket as the default. File naming or alphabetical order can therefore change the fallback after an include is added. Treat the default as an intentional safety net, not as a substitute for correcting a hostname mismatch.

Inspect the complete listener set

In the nginx -T output, group blocks by socket: IPv4 port 80, IPv6 port 80, IPv4 port 443, and IPv6 port 443 where applicable. Record which block is marked default_server in each group. A configuration can be correct on IPv4 port 80 and still fail on IPv6 port 80 or on either 443 socket.

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

5. Correct server_name matching

List the exact hostnames clients send. If visitors use both the bare domain and the www form, include both deliberately:

server_name example.com www.example.com;

Check spelling, punctuation, and the level of each name. A typo, an omitted subdomain, or a wildcard that does not cover the requested label sends the request to another matching block or to the default. Wildcards do not match arbitrary depth: a pattern intended for one subdomain level may not match a name with additional labels.

Remember that the name used for testing matters. A browser request to https://www.example.com carries a different host from https://example.com; an IP-address URL carries neither name. Test each public hostname separately and decide whether one should redirect to another or serve the same content.

Use a temporary routing marker

When several blocks look similar, give the suspected block a temporary, unmistakable response or header, then test with the real hostname. Remove the marker after confirming the route. This is safer than inferring selection from a shared document root, because two blocks may currently point to identical files while still having different TLS, proxy, or logging settings.

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

6. Separate routing from content configuration

Once the request reaches the intended block, inspect what that block does with it. A correctly selected server can still show an unexpected page or status when its content directives point somewhere else.

Static files

  • root determines the filesystem base used to build a file path.
  • index controls which filename Nginx tries for a directory request.
  • location matching can send a URI to a different root, a static file, or a special handler.

Verify that the requested URI maps to the file you expect, that the file exists under the effective root, and that the Nginx worker can traverse the directories and read the file. A 404 after the correct block is selected is a content-path issue, not evidence that the server block was ignored.

Reverse proxy applications

For proxied sites, inspect proxy_pass and the matching location. Confirm that the upstream address and port are the intended ones and that the application is running. An upstream connection failure, an application-generated error, or a URI rewrite can look like a wrong virtual host when the request actually selected the correct block.

Check the response status and the Nginx error log together. The access log tells you that Nginx received the request; the error log can identify an unavailable upstream, a missing file, or a permission problem.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

7. Watch access and error logs during a real request

Generate one request with the exact hostname and protocol that fails, then inspect the logs immediately. The access log confirms whether the request reached Nginx and records the resulting status. The error log explains startup, filesystem, upstream, and TLS failures.

The error_log directive controls the destination and severity. If you are unsure where the active logs are written, inspect the effective configuration and the compiled defaults reported by nginx -V. A common diagnostic mistake is watching a log file from an inactive configuration while the running instance writes elsewhere.

Increase detail only for the affected server

After ordinary logs identify a routing question that remains unresolved, assign a per-server error_log with debug severity in the suspected block, validate with nginx -t, and reload. Debug logging can expose request-processing details without making every virtual host verbose. Remove or reduce the setting after the test; sustained debug output can grow quickly and obscure normal errors.

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

8. Troubleshoot HTTPS separately

TLS negotiation occurs before Nginx receives the HTTP request. If the 443 listener or its default TLS server is wrong, a browser can receive the wrong certificate before HTTP server_name routing has a chance to select the intended content block.

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

Check the 443 block first

  1. In nginx -T, find every listen 443 ssl line for the address families in use.
  2. Confirm the intended certificate and private-key directives are in the block that should answer the hostname.
  3. Check that the certificate files exist, are readable by the Nginx master process, and cover the hostname being tested.
  4. Ensure an unintended 443 default_server is not catching the connection.
  5. Make a fresh HTTPS request using the real hostname and compare the certificate, status, and response body.

If HTTP reaches the right site but HTTPS does not, do not assume the port-80 block controls TLS. Each protocol has its own listening socket, default, certificate, and logs.

Use logs to distinguish TLS from HTTP errors

A certificate warning or handshake failure points to the TLS listener, certificate, key, protocol, or address-family path. A valid certificate followed by the wrong page points to 443 server selection or content directives. Keep those stages separate when reading browser errors and Nginx logs.

9. Fix server-name hash startup errors only when present

Large numbers of names or unusually long names can exceed the defaults used to build Nginx’s server-name hash. The startup error may say that Nginx could not build the server_names_hash. Apply the remedy only when that specific error appears:

  • Increase server_names_hash_bucket_size when the logged condition concerns bucket size.
  • Increase server_names_hash_max_size when the logged condition concerns the maximum hash size.

Place the setting in the appropriate HTTP configuration context, run sudo nginx -t, and reload only after the test succeeds. Changing hash values will not repair a DNS, listener, include, or hostname mismatch.

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

10. Apply the smallest verified change

When several fixes seem possible, compare them in this order:

  1. Destination: Does the hostname reach the intended IP and address family?
  2. Socket: Does the request arrive on the address and port covered by the block?
  3. Name: Does the Host value exactly match the intended server_name?
  4. Loading: Does nginx -T prove that the edited file is included?
  5. Fallback: Is the default server for that socket deliberate?
  6. Evidence: Do access and error logs show the expected block and outcome?

Change one layer at a time. After each edit, run sudo nginx -t, reload the service, repeat the same request, and record the result. This prevents a content change from masking a routing error and makes rollback straightforward.

Practical diagnostic sequence

Use this condensed runbook when a site appears to ignore its server block:

  1. Run sudo nginx -t; fix every reported error.
  2. Run sudo nginx -T; verify the intended file, listeners, names, roots, proxies, and logs are present.
  3. Run nginx -V; confirm the active binary’s configuration path matches the files you edited.
  4. Verify DNS points to this machine on IPv4 and, if published, IPv6.
  5. Check the exact listen address and port for the failing protocol.
  6. Check exact hostnames, aliases, and wildcard scope in server_name.
  7. Identify one intentional default server for each address-and-port combination.
  8. For HTTPS, validate the 443 certificate, key, listener, and TLS logs independently.
  9. After routing is proven, inspect root, index, location, and proxy_pass.
  10. Watch access and error logs while repeating the real request.
  11. Use per-server debug logging only if normal logs cannot explain the selection.

When the default Nginx page is actually expected

The default page is not proof that Nginx is malfunctioning. It is the normal response when the request reaches a socket but no server_name matches, when you browse to an IP address, or when the intended file is not included. It can also be the deliberate default chosen for an unknown hostname. Replace or disable that fallback only after confirming that the intended hostname, address, port, and include path are correct; otherwise you may hide the diagnostic signal and make future misroutes harder to recognize.

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

Final verification checklist

  • sudo nginx -t succeeds.
  • sudo nginx -T contains the block you edited.
  • nginx -V identifies the configuration path you expect.
  • DNS sends the hostname to this server on every published address family.
  • The request’s port and local address match a deliberate listen directive.
  • The exact Host value appears in server_name.
  • Only the intended block is default for each relevant socket.
  • The 443 block has the correct certificate and key for HTTPS.
  • root, index, location, and proxy_pass point to the intended content.
  • Access and error logs confirm the request and explain any remaining failure.

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.

DNSHTTPSLinuxNGINXserver blocksvirtual hostsWeb server troubleshooting

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.

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.