October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober 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 Fix Nginx Server Blocks That Work Only Intermittently

Intermittent Nginx virtual-host behavior is usually a deterministic routing difference. This guide shows how to prove the selected listener and server block, correct IPv4/IPv6 and default-server configuration, test TLS and Host matching, and separate routing faults from reverse-proxy failures.
Length11 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

An Nginx server block is selected deterministically, so “intermittent” behavior usually means different requests are taking different paths. The common causes are an IPv4 request reaching a different listener than IPv6, a hostname resolving to multiple addresses, a missing or unexpected Host value selecting a default server, overlapping server_name patterns, or a correctly selected block forwarding to an unhealthy upstream.

Fix the problem by proving which listener and server name handled each request, then correct coverage, defaults, name matching, TLS configuration, or upstream health. Do not start by editing the file that looks relevant: Nginx may be loading a different file, an include may override it, or the failure may occur after virtual-server selection.

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 processes a request in stages. It first compares the destination address and port with the listen directives. Only the blocks attached to that socket can be considered. If several blocks share the socket, Nginx compares the HTTP Host header with their server_name values.

  1. Listener match: the request’s destination IP address and port must match a listen socket.
  2. Name match: among blocks on that socket, Nginx evaluates the Host value against exact, wildcard, and regular-expression names.
  3. Fallback: if the name is absent or does not match, Nginx uses that socket’s default server.

The default is the first server listed for a socket unless a block explicitly uses default_server on its listen directive. The official Nginx documentation states that a request whose value matches no server name, or that has no Host header, is routed to the default server for that port. This is why two requests from the same browser can show different content: they may use different address families, ports, hostnames, or TLS handshakes.

#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.

Match the symptom to the likely fault

Observed behavior First check Likely explanation Typical correction
Default Nginx page appears only for some users Compare IPv4 and IPv6 responses and inspect the default block for each socket One address family lacks the intended listener, or an unmatched host is reaching a different default Add matching listeners and declare an intentional default_server
One hostname sometimes serves another site Inspect DNS answers, the Host header, and overlapping names Requests reach multiple addresses or match a wildcard/regex with unexpected priority Align DNS and listeners; use exact names where possible
HTTP works but HTTPS redirects or serves the wrong certificate Check both port 80 and 443 blocks, SNI, and 443 defaults The HTTPS socket has different coverage or the TLS handshake selects another server Configure equivalent names and explicit defaults on 443
The correct site loads, then fails or recovers later Read upstream timing and connection errors Virtual-server selection is correct, but an upstream is failing or temporarily marked unavailable Repair the backend or upstream policy; do not change server_name blindly
Edits have no visible effect Run nginx -T and inspect include paths The edited file is not loaded, another block wins, or the configuration was never reloaded Change the active configuration, validate it, and reload deliberately

Capture a baseline before changing anything

Record the exact failure while it is reproducible. Save the URL, time in UTC, client network, response status, response headers, and whether the request used HTTP or HTTPS. If a monitoring system reports the issue, preserve its source address and resolved destination.

Resolve every address published for the name:

dig +short A example.com
dig +short AAAA example.com

Several A or AAAA records mean different clients can reach different servers. Even one host with both record types can appear inconsistent when IPv4 and IPv6 terminate on different machines or listeners.

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

Inspect the complete loaded configuration, not only the file you edited:

sudo nginx -T

Save the output so you can compare it after a change. Search it for every listen, server_name, default_server, include, and proxy_pass. Look for duplicate sockets, an unexpected default, a missing IPv6 listener, overlapping names, and a server block that is absent because its file is outside the active include path.

Test IPv4, IPv6, and Host values separately

Never treat one successful browser request as proof that all paths work. Force each address family and preserve the intended hostname in the request. For HTTPS, also preserve the hostname during the TLS handshake so the server receives the correct SNI value.

curl -4 -i https://example.com/
curl -6 -i https://example.com/
curl -4 -i --resolve example.com:443:203.0.113.10 https://example.com/
curl -6 -i --resolve example.com:443:2001:db8::10 https://example.com/

Replace the example addresses with the actual A and AAAA answers. The --resolve form sends the request to a chosen address while retaining the URL hostname, which keeps both the HTTP Host header and HTTPS SNI consistent. For plain HTTP, use the same technique with port 80.

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

To test name selection independently of DNS, send a request to an address while supplying different hostnames:

curl -i -H 'Host: example.com' http://203.0.113.10/
curl -i -H 'Host: other.example.com' http://203.0.113.10/
curl -i -H 'Host: unknown.example' http://203.0.113.10/

The known name should reach its intended block. The unknown name should reach the deliberately configured fallback, not an accidental production site. If IPv4 and IPv6 return different headers, bodies, status codes, or certificates, you have isolated a listener or address-family problem rather than an intermittent application bug.

Make listener coverage and defaults explicit

Cover both address families on every required port

IPv4 and IPv6 are separate sockets. If a hostname publishes both, configure both unless you intentionally want one family disabled. A typical HTTP block might look like this:

server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;
    return 301 https://example.com$request_uri;
}

Use the same principle on port 443, including the TLS directives and all names that should be valid there:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name example.com www.example.com;
    ssl_certificate /etc/ssl/example/fullchain.pem;
    ssl_certificate_key /etc/ssl/example/privkey.pem;
    proxy_pass http://app_backend;
}

Do not assume that a port-80 listener automatically covers 443, or that an IPv4 listener covers IPv6. Each address-and-port combination has its own server selection and default.

Declare the fallback server

In a multi-site configuration, choose the response for unknown names explicitly. Put default_server on the intended fallback for each socket, including both families and both HTTP and HTTPS when they are in use:

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)
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;
    return 444;
}

server {
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;
    server_name _;
    ssl_certificate /etc/ssl/fallback/fullchain.pem;
    ssl_certificate_key /etc/ssl/fallback/privkey.pem;
    return 444;
}

The underscore is conventionally used as a catch-all name; the decisive setting is default_server. Use a suitable response for your environment: a controlled error, a redirect to a canonical hostname, or a neutral landing page. Avoid allowing an unrelated site’s content to become the accidental fallback.

Correct server_name matching

Use exact names for production hostnames whenever possible:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
server_name example.com www.example.com api.example.com;

Wildcard names cover a defined label position, such as *.example.com. They do not automatically cover the bare example.com; list that name separately if it is required. A leading wildcard and a trailing wildcard have different scopes, so check that the pattern actually matches the hostname clients send.

Regular-expression names can overlap many hosts and are evaluated after exact and wildcard matches according to Nginx’s documented priority rules. A broad regex can capture a request that you expected another block to handle. Keep regex patterns narrow, document why they exist, and remove them when an explicit name list is sufficient.

Remember that the name used for an HTTP redirect must also be present on the destination’s HTTPS block. A request for www.example.com redirected to https://example.com needs a valid 443 configuration for example.com; otherwise the redirect appears to work while the destination lands on the wrong default.

Check TLS, SNI, and redirect consistency

HTTPS adds a selection step before HTTP routing: the client sends a TLS Server Name Indication value, and Nginx chooses a certificate context on the 443 socket. After the handshake, the HTTP Host header must still match the intended server block. A missing name, an old client without SNI, or a 443 default with the wrong certificate can make HTTPS appear intermittent even when port 80 is correct.

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

For every HTTPS site, verify:

  • The intended block listens on 443 for every published address family.
  • Its server_name list contains every canonical and alias hostname.
  • The certificate covers each hostname clients use.
  • The 443 fallback is explicit and has a deliberate certificate and response.
  • HTTP redirects point to a hostname that is configured on 443.

Test the certificate and response by address while retaining the hostname:

curl -4 -vk --resolve example.com:443:203.0.113.10 https://example.com/
curl -6 -vk --resolve example.com:443:2001:db8::10 https://example.com/

Compare the certificate subject or SANs, status, Location header, and response body. A certificate mismatch identifies TLS selection; a matching certificate followed by the wrong body points to HTTP server-name selection or an upstream issue.

Prove which block handled the request with logs

Access and error logs are the fastest way to distinguish routing from backend delay. During reproduction, watch the relevant files with your platform’s log viewer or tail -F. Add a temporary access format that records the request host, selected server, socket, and upstream timings:

log_format routing '$remote_addr $host $server_name $server_addr:$server_port '
                  '$request $status $request_time '
                  '$upstream_connect_time $upstream_header_time '
                  '$upstream_response_time $upstream_status';
access_log /var/log/nginx/routing.log routing;

$request_time measures total request handling time. The upstream variables show connection, response-header, and total response timing when proxying. Empty upstream fields generally mean the request never reached an upstream, which directs attention back to server selection, static handling, or an early client failure.

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

Logging $host and $server_name together is useful: the former is the value supplied by the client (normalized by Nginx), while the latter identifies the server context that accepted the request. Include the listening address and port so IPv4 and IPv6 records can be compared directly. Remove or reduce temporary verbose logging after diagnosis if volume or sensitive-data retention is a concern.

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

Raise debug logging only for the affected virtual host

If ordinary logs do not reveal the selection, use Nginx’s debug logging guidance. Find the active error_log directive and temporarily set its level to debug in the affected server block, rather than enabling debug output globally. This keeps unrelated traffic from overwhelming the log and makes the relevant connection easier to follow.

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.

Debug logging requires an Nginx build with debug support. Check the build options with:

nginx -V 2>&1 | grep -- --with-debug

Validate the configuration, reload, reproduce one controlled request, and then return the log level to its previous setting. Debug logs can be very large and may contain request details, so use a short window and protect the files appropriately.

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

Separate virtual-server selection from reverse-proxy health

A correctly selected block can still fail intermittently because its upstream is unavailable. Once logs show the expected $server_name, inspect connection errors, upstream status codes, and timing fields before changing listeners or names.

Nginx can retry another server in an upstream group after communication errors, depending on the proxy configuration. Passive health checks can mark a repeatedly failing upstream unavailable for a period controlled by fail_timeout. During that period, requests may fail, be retried, or recover when the peer becomes eligible again. That pattern looks like random routing to a user but is a backend-health event.

Use an explicit upstream definition and keep its failure policy intentional:

upstream app_backend {
    server 10.0.0.11:8080;
    server 10.0.0.12:8080;
}

server {
    listen 80;
    listen [::]:80;
    server_name app.example.com;
    location / {
        proxy_pass http://app_backend;
        proxy_next_upstream error timeout http_502 http_503 http_504;
    }
}

Do not interpret a 502, 503, or 504 as proof that the wrong server block won. Correlate the status with upstream timing and error-log messages. Test each backend directly from the Nginx host, verify firewall and service health, and check whether all peers fail or only one. If the selected block and upstream are both correct, investigate application timeouts, connection limits, and deployment changes instead of virtual-host matching.

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.

Validate and reload safely

  1. Save the active baseline: keep the output of nginx -T, representative IPv4 and IPv6 responses, certificates, and relevant log lines.
  2. Edit one logical issue: for example, add the missing IPv6 listener or make the intended default explicit. Avoid combining unrelated proxy changes with routing changes.
  3. Run the deployed binary’s syntax test:
    sudo nginx -t

    Continue only when Nginx reports a successful syntax check and the configuration file test succeeds.

  4. Review the rendered result: run nginx -T again and confirm the changed block is loaded once, on the intended sockets, with the expected names.
  5. Reload during a controlled window:
    sudo systemctl reload nginx

    A reload asks the running master to apply the validated configuration without an abrupt stop. Use your platform’s service manager if it differs.

  6. Repeat the same tests: run the saved IPv4, IPv6, HTTP, HTTPS, known-host, and unknown-host requests. Compare status, headers, certificate, body, and log fields.
  7. Keep a rollback path: if the result is worse, restore the previous configuration, rerun nginx -t, reload, and verify with the same requests.

Choose the fix by failure location

Failure location Evidence Fix focus
Before virtual-server selection Different address family, unmatched socket, or wrong port; logs show an unexpected listener or default Correct listen coverage and explicit defaults
During name matching Same socket but different response for a supplied Host; overlapping exact, wildcard, or regex names Simplify and correct server_name patterns
During TLS negotiation Wrong certificate or handshake failure on 443, often limited to one address Align 443 listeners, SNI names, certificates, and defaults
After proxying begins Expected server context in logs, upstream connection errors or elevated timing Repair backend reachability, timeouts, peer health, or retry policy

Common pitfalls that recreate the problem

  • Editing an inactive file: distributions commonly load a directory of included files. The rendered configuration is authoritative.
  • Relying on declaration order: the first block becomes the default only when no explicit default is declared. Order-based behavior is fragile as sites are added.
  • Configuring only IPv4: a working A record test says nothing about clients that receive an AAAA record.
  • Forgetting the bare name: *.example.com does not replace an explicit example.com entry.
  • Testing by IP without a Host header: that intentionally exercises the default server, not the named virtual host.
  • Changing proxy settings to fix a routing symptom: retries and timeouts cannot make an unmatched hostname select the correct block.
  • Leaving debug logging enabled: it can produce high-volume files and expose request details; disable it after the controlled reproduction.
  • Reloading without validation: a failed syntax check leaves the old configuration running, which can be mistaken for an intermittent result.

A compact verification checklist

  • Every published A and AAAA address reaches the intended Nginx instance.
  • Each required address family has listeners for every used port.
  • The intended fallback is marked default_server on each relevant socket.
  • Exact aliases, wildcard scope, and any regex names are documented and non-overlapping.
  • HTTP redirects lead to names configured on the corresponding 443 block.
  • TLS certificates and SNI behavior match on IPv4 and IPv6.
  • Access logs record host, selected server, socket, status, and request time.
  • Upstream timing and error logs are checked before blaming server selection.
  • The configuration is tested, re-rendered, reloaded, and verified with identical requests.

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.

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.