Find the first response that introduces the wrong hostname, then fix that layer. A wrong domain can come from Nginx selecting the wrong virtual server, an application generating an absolute redirect from its private hostname, or Nginx constructing a redirect from its own server settings. The remedy is different in each case.
Need a server to try this on? Antihost offers Linux VPS plans with NVMe storage, full root access and a 14-day free trial.
Use the procedure below to trace the complete redirect chain, correct host and scheme forwarding, rewrite backend headers only when necessary, and configure intentional www/non-www canonicalization without creating a loop.
As an Amazon Associate I earn from qualifying purchases.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsStart by identifying who generated the wrong redirect
Do not change several directives at once. First capture every hop between the public URL and the final response. The first Location header containing the wrong domain is the most useful clue: it tells you which layer made the decision.
Capture the complete chain with curl
Run the test from a machine that can reach the public endpoint:
#1 Best Overall
- B5 Recipe Book: This hardcover blank recipe book measures 10''×7.3'', containing 150 blank pages, comes with 1 sheet of DIY category stickers, perfect for writing down your own recipes and organizing them in one place.
- Practical Layout - 5 pages of conversion charts show you everything you'll ever need to know in the kitchen. The table of contents will help organize your personal favorite recipes. A back pocket is designed for loose items.
- Easy to Use - This blank cookbook is made of high-quality paper with a beautiful hardcover for long-term use. The sturdy gold double-wire spiral binding makes writing easier and page turning smoother.
- Make Your Own Recipes - This blank cookbook has up to 150 blank pages for you to write in your own recipes, with plenty of space to record ingredients and instructions. You can write down all the special tips for your family members.
- Thoughtful Gift - A personalized recipe book makes a thoughtful gift for your children or newlyweds, and a great gift for housewarming, weddings, bridal showers, anniversaries, or any other occasion.
curl -I -L https://public.example/path
-I requests headers only and -L follows redirects, so the output shows each status code and each Location value. Repeat without -L when you need to inspect only the first response:
curl -I https://public.example/path
Record the status and location at every hop. For example, if the public request first returns Location: http://backend:8080/login, the upstream application exposed its private address. If the first response points to a different public hostname, inspect Nginx virtual-server selection and any deliberate canonicalization rule. If the upstream is correct but a later Nginx-generated redirect changes the host, review Nginx’s redirect settings.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Use the redirect origin to choose the fix
| What the first incorrect response looks like | Likely source | Most focused correction |
|---|---|---|
| The request lands in a block intended for another hostname, or follows an unexpected canonical host | Nginx server selection or an explicit redirect block | Correct server_name, listen/default-server arrangement, or the dedicated return 301 rule |
Location: http://backend:8080/... or another private name |
The proxied application generated an absolute URL | Pass the public host and forwarded context; use proxy_redirect for the response header if required |
| The application receives the public request correctly, but Nginx supplies its own wrong absolute host | Nginx core redirect generation | Review server_name_in_redirect and absolute_redirect |
| HTTP and HTTPS or www and non-www alternate indefinitely | Conflicting canonicalization policies at more than one layer | Choose one owner for canonicalization and remove the competing redirect |
Verify that Nginx selected the intended virtual server
Nginx matches the request’s Host value against server_name within the appropriate listen address and port. If no name matches, the default server for that address and port handles the request. An earlier or default block can therefore issue a redirect before the proxy block you were editing ever runs.
Inspect the loaded, not merely edited, configuration
- Run
nginx -Twith the privileges used to administer Nginx. This prints the complete configuration after included files have been expanded. - Find every
serverblock listening on the affected port, including both the HTTP and HTTPS listeners. - Confirm that the public name appears in the intended block’s
server_name. Check spelling, aliases, and whether an old name is still listed in the same block. - Check which block is marked
default_serverfor that address and port. An unmatched request will use it. - Verify that the TLS listener has the expected certificate and name configuration. A request arriving on 443 can be handled by a different block from the one handling port 80.
Do not assume the file you recently changed is active. Distribution packages commonly include separate files and symlinks, and an include can leave an older block loaded. The output of nginx -T is the authoritative view of what the running configuration will use after reload.
Test host matching without changing DNS
If DNS is still being migrated, send a chosen host header to the server’s address:
curl -I --resolve public.example:443:203.0.113.10 https://public.example/path
Replace the example address with the server’s real address. This preserves the URL host for TLS and HTTP while directing the connection to the selected address. Compare it with a request using the old hostname and with a request that omits the expected name. If only the unmatched request takes the wrong redirect, the default-server arrangement is the issue rather than the proxy application.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Pass the public host and request context to the upstream
For a proxied request, Nginx does not automatically send the browser’s original host as the upstream Host. The reverse-proxy behavior uses the $proxy_host value by default. An application that builds absolute links or login callbacks from that header can consequently redirect a visitor to an internal name or port.
Set the headers in the proxy location
Place the following directives in the location that contains proxy_pass:
location / {
proxy_pass http://app_backend;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
}
Host $hostgives the application the public hostname that Nginx selected.X-Forwarded-Forpreserves the client address chain for applications that use it for logging, redirects, or security decisions.X-Forwarded-Proto $schemetells the application whether the browser connected with HTTP or HTTPS, which prevents an HTTPS request from being downgraded to an HTTP login URL.X-Forwarded-Host $hostsupplies the original host through a separate conventional header when the framework reads that header instead ofHost.
If the public service uses a nonstandard port, determine how the application expects that information. Some frameworks use an X-Forwarded-Port header or the port portion of the original host. Configure the value deliberately rather than assuming that $host includes a port; test an actual redirect from that port.
Configure the application’s trusted-proxy policy
Forwarded headers have no effect if the application ignores them, and accepting them from untrusted clients can be unsafe. In the application, enable its documented trusted-proxy or proxy-awareness setting for the Nginx address, then specify which forwarded scheme and host headers it may use. The exact setting depends on the framework. Verify it by logging the request’s perceived scheme, host, and port, then trigger a redirect such as a login or trailing-slash change.
Do not solve an application trust problem by blindly copying arbitrary client-supplied X-Forwarded-Host values. Nginx should overwrite the headers at the trusted boundary, and the application should trust only the proxy path you control.
Rewrite absolute backend redirects with proxy_redirect
Correct forwarding headers first. If the application still returns an absolute private URL, rewrite that response at the proxy. The proxy_redirect directive changes Location and Refresh response headers from the proxied server.
Replace a backend origin with the public request path
location / {
proxy_pass http://app_backend;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect http://backend:8080/ /;
}
With this form, a response such as Location: http://backend:8080/login becomes a redirect on the current public origin, preserving the request’s host and path base.
Replace it with a fixed public origin
location / {
proxy_pass http://app_backend;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect http://backend:8080/ https://public.example/;
}
Use a fixed public origin only when every request through this location is intentionally served from that host. If several public names share the proxy and the requested host should be preserved, a relative replacement or a variable-based public value is safer than hard-coding one name.
Watch for path prefixes and ports
The text on the left side must match the origin and path that the upstream actually emits. Capture the exact header with curl -I; do not guess whether the application includes a trailing slash, a path prefix, or a nondefault port. A rule for http://backend:8080/ will not match a header that says http://backend:8080/app/ unless the replacement pattern accounts for that path.
Keep rewriting narrow. A broad substitution can hide a broken application configuration, alter redirects for unrelated upstreams, or turn an intentionally different origin into the public one. After adding the rule, test login, logout, password-reset, API, and trailing-slash paths separately.
Rank #2
- Create a Culinary Legacy: The Pipilo Press Blank Family Cookbook Recipe Binder offers a timeless platform for chronicling beloved recipes. With its hardcover and spiral binding, this recipe book to write in your own recipes ensures durability and ease of use for generations
- Thoughtful Gifting Choice: This book for writing recipes is an ideal present for various occasions, adding a personal touch to celebrations. Its elegant design makes it perfect for moms cookbook DIY projects or anyone passionate about preserving family traditions
- Durable Design Features: Constructed with a 300gsm cardstock cover and matte lamination, this cookbook you can write in ensures longevity. Its spiral-bound format provides convenient access to pages, making it a practical tool for everyday use
- Organized Recipe Storage: The included memo pocket offers a space to store handwritten notes or recipe cards, enhancing its functionality. This feature transforms the recipe book for moms into a sentimental family memento
- Ample Writing Space: Measuring 6.5 x 8.2 inches, this blank spiral family recipe cookbook offers plenty of room for detailed notes. It is perfect for jotting down ingredients, preparation methods, and serving suggestions for a complete culinary record
Correct redirects generated by Nginx itself
Some redirects never reach the application. Nginx can generate absolute redirects for its own processing, and two core settings determine which host appears.
server_name_in_redirect
server_name_in_redirect controls whether an absolute redirect uses the primary name from the selected server block or the host supplied by the request. If the block’s primary name is an internal or old hostname, Nginx can expose it even though the browser requested the public name. Review this setting together with the ordering and contents of server_name.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →absolute_redirect
absolute_redirect controls whether Nginx emits absolute URLs in redirects. When the deployment requires relative redirects, disabling absolute redirects can avoid a host being inserted by Nginx. This is a policy decision: relative locations are less explicit for clients and do not replace a correctly configured canonical hostname.
These directives affect redirects that Nginx constructs; they do not rewrite an application’s response. If the bad host is already present in an upstream Location, use the header and application fixes described earlier.
Implement intentional www/non-www canonicalization in separate blocks
Canonicalization is different from preserving the host. If the site deliberately chooses one public name, make that policy explicit and keep the redirect-only server separate from the application proxy.
server {
listen 80;
server_name old.example.com;
return 301 https://www.example.com$request_uri;
}
server {
listen 443 ssl;
server_name www.example.com;
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://app_backend;
}
}
Add equivalent redirect blocks for every alternate name you intentionally support, such as the non-www HTTPS name. Ensure that the destination block does not redirect back to the source. Keep certificates valid for every HTTPS name that must receive a redirect; a browser must complete TLS before it can follow the HTTP response.
Recommended Free Tools
Use an explicit return 301 rather than an if-based host switch inside the main proxy block. Separate server blocks make the policy visible to Nginx’s virtual-server selection and avoid a cumbersome, ineffective conditional redirect pattern.
Preserve scheme and port across TLS termination
A common arrangement terminates TLS at Nginx and sends plain HTTP to the application. Without the original scheme, the application sees an HTTP request and may redirect to HTTP even though the visitor used HTTPS. Set X-Forwarded-Proto $scheme and configure the application to trust it.
Port errors follow the same pattern. A backend listening on 8080 is not evidence that the public URL uses 8080. Forward or configure the external port separately, and make sure the application generates URLs from the external port rather than its listening socket. Test both the default HTTPS port and any deliberately exposed alternate port.
Diagnose common loops and wrong-host symptoms
HTTPS to HTTP and back again
If the browser requests HTTPS, Nginx forwards HTTP, and the application redirects to HTTPS repeatedly, the application is not recognizing the forwarded scheme or does not trust the proxy. Confirm the header at the application boundary and its trusted-proxy setting. Do not add another Nginx redirect until the application reports HTTPS for the original request.
Free tools Windows power users keep installed
One-click scans. No signup required.
www and non-www alternate
Inspect each hop with curl -I -L. If both server blocks issue 301 responses, choose one canonical destination. The canonical block should serve the request directly; only the alternate block should redirect.
The old hostname appears only after login
Basic pages may be relative while the authentication system constructs an absolute callback URL. Check the login response’s Location, then verify that the application receives the public Host, X-Forwarded-Host, and X-Forwarded-Proto. If those values are correct but the response remains wrong, apply a narrowly scoped proxy_redirect or correct the application’s external-base-URL setting.
The proxy works by IP but not by name
An IP request may fall into the default server while the named request matches a different block. Compare the two requests with explicit Host values and inspect nginx -T. Correct the matching server_name and default arrangement rather than changing upstream headers.
The fix appears ineffective
Run nginx -t before reloading. A successful syntax test does not reload workers, so apply the configuration with your service manager’s reload operation, then repeat the same curl command. If command-line results are correct but a browser still jumps to the old host, remember that browsers can cache 301 responses. Test in a clean session or with a new path only after the server-side chain is verified.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Validate and roll out the change safely
- Save the current configuration or use your normal version-control checkpoint.
- Run
nginx -tand fix every reported error before reloading. - Reload Nginx using the method appropriate to your installation.
- Repeat
curl -I -L https://public.example/pathfor a normal page, a login endpoint, and a path that previously exposed the wrong host. - Check that the final status is the expected application response, that every intermediate
Locationuses the intended scheme and host, and that no private hostname or backend port leaks. - Test alternate names, HTTP-to-HTTPS behavior, and any nonstandard public port you support.
Only after these checks should you clear browser or intermediary caches. A cached permanent redirect can conceal a successful server change or make a repaired endpoint appear broken.
Quick Recap
Choose the smallest fix that matches the evidence
| Evidence | Change to make | What not to change |
|---|---|---|
| Wrong block handles an unmatched or misspelled host | Fix server_name, listen/default-server selection, or the intended redirect block |
Do not rewrite upstream headers to compensate for wrong virtual-server matching |
| Upstream sends its own hostname or port | Set public host and forwarded context; add a precise proxy_redirect rule if the response remains absolute |
Do not change canonical-domain policy unless that is the stated goal |
| Nginx creates the bad absolute URL | Review server_name_in_redirect and absolute_redirect |
Do not expect proxy_redirect to alter a redirect Nginx generated before proxying |
| Business policy requires one canonical name | Use separate redirect and destination server blocks with explicit return 301 |
Do not combine opposing www/non-www rules in the same request path |
Final troubleshooting checklist
- Have you recorded the first incorrect
Locationheader rather than only the final URL? - Does
nginx -Tshow the expectedserver_name, listen port, TLS block, and default-server behavior? - Does the proxy send
Host $hostwhen the application must know the public hostname? - Are
X-Forwarded-Protoand, where needed,X-Forwarded-Hostpresent and trusted only from Nginx? - Does an upstream absolute location require a narrowly matched
proxy_redirectrule? - Are Nginx-generated absolute redirects consistent with
server_name_in_redirectandabsolute_redirect? - Is canonical www/non-www behavior implemented by one-way, separate server blocks?
- Did
nginx -t, reload, and a fresh multi-hop curl test all succeed before relying on browser results?
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.




