The reliable NGINX pattern for moving a domain is a dedicated, redirect-only server block for the old hostname. Use an unconditional return 301 https://new.example.com$request_uri; so the destination receives the original path and query string. Keep the destination site in its own virtual server, configure its TLS endpoint separately, test with a temporary status when appropriate, and verify the actual Location header before making a permanent migration.
Need a server to try this on? Antihost offers Linux VPS plans with NVMe storage, full root access and a 14-day free trial.
What a correct NGINX domain redirect does
A domain redirect is an HTTP response from NGINX, not a rewrite performed by your application. A client requests a URL on the old host, NGINX selects a virtual server using the request’s Host name, and that server returns a redirect response with a Location header. The client then requests the new URL.
As an Amazon Associate I earn from qualifying purchases.
For a straightforward hostname move, the redirect block should do one thing: match the old hostname and send every request to the new hostname. NGINX’s documented conversion guidance describes a separate server for the old name as the right approach. This keeps migration logic out of application code and avoids unnecessary conditional rules.
The basic old-domain-to-new-domain configuration
Place this block in the configuration loaded by NGINX. Replace the example names with the exact hostnames involved in your migration:
#1 Best Overall
- [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
- [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
- [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
- [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
- [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.
server {
listen 80;
server_name old.example.com;
return 301 https://new.example.com$request_uri;
}
listen 80 receives plain HTTP traffic. server_name limits the rule to the old hostname, and return 301 immediately sends a permanent redirect. The $request_uri variable contains the original path and query string, so a request for /docs/setup?edition=2 is redirected to https://new.example.com/docs/setup?edition=2.
Do not replace $request_uri with a bare slash unless the intentional behavior is to send every old URL to the new site’s homepage. Collapsing all paths can strand deep links, bookmarks, search results and links shared by users.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Keep the destination in a separate serving block
The old host’s block should not also serve the destination application. A typical apex-to-www arrangement has one redirect block and one block that actually serves the canonical site:
server {
listen 80;
server_name example.com;
return 301 https://www.example.com$request_uri;
}
server {
listen 443 ssl;
server_name www.example.com;
ssl_certificate /etc/nginx/ssl/www.example.com.crt;
ssl_certificate_key /etc/nginx/ssl/www.example.com.key;
# application locations...
}
Here, example.com is only the old hostname on port 80, while www.example.com is the destination HTTPS site. The destination block needs a certificate whose names cover www.example.com. The private key must be protected, but it must remain readable by the NGINX master process so TLS can start.
Redirecting apex and www consistently
Choose one canonical hostname and redirect the other to it. For a www canonical name:
server {
listen 80;
server_name example.com;
return 301 https://www.example.com$request_uri;
}
server {
listen 80;
server_name www.example.com;
return 301 https://www.example.com$request_uri;
}
If the canonical site also accepts HTTPS requests on the noncanonical hostname, create the equivalent HTTPS redirect block for that hostname, with the certificate needed to complete the TLS handshake before NGINX can issue the redirect. The serving block remains responsible for the canonical name.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
For a non-www canonical name, reverse the names:
server {
listen 80;
server_name www.example.com;
return 301 https://example.com$request_uri;
}
server {
listen 80;
server_name example.com;
return 301 https://example.com$request_uri;
}
Use exact names when only these two hosts should be redirected. A broad wildcard can capture subdomains that were never meant to move.
Rank #2
- 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
- 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
- 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
- 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
- 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.
Forcing HTTP to HTTPS
HTTP-to-HTTPS requires two pieces: a port-80 redirect and a separately configured port-443 TLS server. The HTTP block can cover both hostnames when both should end at the same canonical HTTPS host:
server {
listen 80;
server_name example.com www.example.com;
return 301 https://www.example.com$request_uri;
}
The HTTPS endpoint must be configured independently:
server {
listen 443 ssl;
server_name www.example.com;
ssl_certificate /etc/nginx/ssl/www.example.com.crt;
ssl_certificate_key /etc/nginx/ssl/www.example.com.key;
# application locations...
}
NGINX documentation also shows a form using https://$server_name$request_uri. A literal canonical hostname is often clearer when you are deliberately consolidating apex and www, because it makes the target explicit rather than depending on whichever name was selected for that server.
Do not assume the redirect itself replaces TLS configuration. A browser must establish HTTPS with a certificate that covers the requested destination hostname before it can receive content from that HTTPS server. An incomplete 443 block can therefore produce a certificate warning or handshake failure instead of a clean redirect.
return or rewrite: which directive belongs here?
| Situation | Preferred directive | Reason |
|---|---|---|
| Every request in a server goes to one hostname | return |
Direct, readable and does not require a regular expression |
| A location needs a pattern-based URI transformation | rewrite |
Supports conditional or regex-based path changes |
| Temporary testing of a redirect | return 302 or return 307 |
Makes the temporary intent visible in the response |
| Permanent domain migration | return 301 |
Communicates that the old URL has moved permanently |
The return directive is valid in both server and location contexts. For an unconditional domain mapping, placing it at server level lets NGINX answer before application locations are evaluated. A rewrite rule can work, but regex and control flow make a simple hostname redirect harder to inspect and easier to misconfigure.
Choosing 301, 302 or 307
Use 301 when the old domain has permanently moved and you are ready for clients and intermediaries to treat the target as the lasting URL. Use 302 or 307 while testing, during a temporary campaign, or whenever the destination may change back.
| Status | Use it when | Operational caution |
|---|---|---|
| 301 | The domain or canonical hostname has permanently changed | Browsers and intermediaries may cache it, making mistakes difficult to undo quickly |
| 302 | The redirect is temporary or under validation | Do not leave it in place if the move is genuinely permanent |
| 307 | You need a temporary redirect while retaining the request method semantics | Use it deliberately and test clients that submit forms or other non-GET requests |
A redirect is an HTTP response, so verify the status code and Location header directly. Browser behavior alone can hide a stale cached 301 or make a malformed redirect appear to work after several requests.
Free tools Windows power users keep installed
One-click scans. No signup required.
Rank #3
- [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
- [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
- [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
- [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
- [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by
How NGINX chooses the virtual server
The server_name directive determines which virtual server receives a hostname. NGINX supports exact names, wildcard names and regular-expression names, and applies documented matching priorities when selecting among them.
Exact names
An exact declaration such as server_name old.example.com; is the clearest choice for a single-domain migration. It limits the redirect to the host you have identified and makes configuration review straightforward.
Wildcards
A wildcard can be appropriate when every matching subdomain is intentionally sent to one destination. It is risky when subdomains have different applications, owners or migration dates. A wildcard that catches an administrative, API or customer-specific hostname can create an unexpected redirect.
Regular expressions and duplicate declarations
Regular-expression names and duplicate or overlapping declarations can make the winning block non-obvious. If a redirect appears to be ignored, inspect all loaded configuration files for another server_name declaration and verify which block is selected for the requested host.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minutePreserving paths and query strings correctly
The safest general-purpose target is the new origin followed immediately by $request_uri:
return 301 https://new.example.com$request_uri;
That variable carries both the path and the query string. Examples include:
| Incoming request | Redirect target |
|---|---|
http://old.example.com/ |
https://new.example.com/ |
http://old.example.com/docs/setup |
https://new.example.com/docs/setup |
http://old.example.com/docs/setup?edition=2 |
https://new.example.com/docs/setup?edition=2 |
Only omit the original URI when the migration requirement explicitly says that all requests should converge on one replacement URL. If old and new sites use different path structures, create deliberate, documented path mappings rather than silently discarding the path.
Rank #4
- Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
- Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
- All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
- Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
- Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.
A safe deployment procedure
- Back up the active configuration. Save the files that define the relevant HTTP and HTTPS servers so you can restore the previous behavior if the redirect is wrong.
- List the exact old hostnames. Decide whether the move covers an apex name,
www, subdomains or only one legacy host. Put only the intended old names in the redirect block. - Add the redirect server. Use an unconditional
returnand append$request_uriunless intentionally collapsing paths. - Confirm the destination TLS server. The destination must have a separate
listen 443 sslserver withssl_certificateandssl_certificate_key. Confirm the certificate names include the destination hostname. - Validate syntax. Run
nginx -tbefore reloading. Treat any syntax or duplicate-name warning as a deployment blocker until you understand it. - Reload using the host’s normal service manager. Use the service-management procedure appropriate to the machine rather than stopping the server unnecessarily.
- Test both schemes and host variants. Check HTTP and HTTPS, apex and
wwwwhere relevant, a representative deep path, a URL with a query string and an unknownHostheader. - Inspect the response itself. Use a client such as
curl -Iand confirm the status, exactLocation, certificate behavior and number of hops.
For example, these checks expose the headers without downloading the response body:
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutecurl -I http://old.example.com/docs/setup?edition=2
curl -I https://old.example.com/docs/setup?edition=2
curl -I http://example.com/
curl -I http://www.example.com/
Follow a redirect separately when you need to inspect the final endpoint, but first test without automatic following so the original status and Location are visible.
Testing an unknown or unexpected Host
Requests whose host does not match an intended server_name can be handled by a default server. That behavior is separate from the planned domain move and should be deliberate. Test an unknown host independently and confirm that it does not expose the wrong application or redirect arbitrary names to your canonical site.
A broad default redirect may be useful in a controlled environment, but it can also hide DNS mistakes and capture hostnames that should have been rejected. Keep the default policy explicit and document why it exists.
Troubleshooting the common failure modes
Redirect loop
A loop usually means the destination hostname is also matched by the redirect-only block, or an upstream proxy is already forcing HTTPS while NGINX constructs a target with the wrong scheme. Make the old and destination names distinct in their respective blocks, then inspect each hop’s Location header. If a proxy sits in front of NGINX, verify which component terminates TLS and which component is responsible for the redirect.
Path or query string disappears
Check the target expression. A destination ending only in / intentionally sends every request to the root. Use https://new.example.com$request_uri when the old path and query must survive unchanged.
The wrong virtual server answers
Look for a typo, wildcard, duplicate server_name or an unexpected default server. NGINX’s name-selection rules decide which block wins; editing a block that is not selected cannot change the response. Test the exact hostname and inspect the full loaded configuration.
Best Value
TLS warning after the redirect
The destination certificate may not cover the hostname, or the 443 server may be missing its certificate directives or SNI-compatible configuration. Fix the destination HTTPS endpoint before relying on the redirect. A valid HTTP redirect cannot compensate for a certificate mismatch on the target.
Unexpected hostname capture
An unmatched host may be falling into the default server. Define a deliberate default policy and test it with an unknown host instead of assuming every request will land in the migration block.
Old behavior persists after changing the file
First confirm that NGINX passed nginx -t and was reloaded. Then inspect the response headers directly. If a 301 was previously served, a browser or intermediary may still be using its cached result; validate future changes with a controlled hostname or a temporary status before committing another permanent redirect.
Patterns for common migrations
Old domain to a new domain, preserving everything
server {
listen 80;
server_name old.example.com old.example.net;
return 301 https://new.example.com$request_uri;
}
Listing both legacy names is appropriate only when both are intentionally moving to the same destination. If one old name needs a different target, give it its own block.
HTTP and www to one HTTPS canonical host
server {
listen 80;
server_name example.com www.example.com;
return 301 https://www.example.com$request_uri;
}
This handles plain HTTP for both names. The canonical www site still needs its separate 443 serving block, and HTTPS requests arriving on a noncanonical name need a certificate-backed redirect block if you want them consolidated as well.
One legacy subdomain to another hostname
server {
listen 80;
server_name legacy.example.com;
return 301 https://new.example.com$request_uri;
}
Use the narrowest hostname scope that matches the migration. Do not convert this to a wildcard merely to reduce the number of lines unless every subdomain truly shares the same destination.
Recommended Free Tools
Operational decisions before switching to 301
- Is the move permanent? If not, use 302 or 307 while validating.
- Which host is canonical? Decide apex versus
wwwbefore writing the target. - Should paths survive? Keep
$request_uriunless a root-only destination is intentional. - Does the destination have TLS coverage? The certificate must include the exact HTTPS hostname.
- Could another layer redirect first? Check load balancers, proxies and application-level redirects for conflicting schemes or hosts.
- Can you reverse the change? Keep a backup and remember that permanent redirects may remain cached after configuration is restored.
What to verify in the final response
A successful test should show the status you chose, a single correct Location target for the tested request and a reachable destination. Test a root URL, a deep URL, a query string, each intended hostname and both schemes that users may enter. Count the hops: an old HTTP host that redirects to an intermediate HTTPS host which then redirects to the canonical hostname works, but a direct one-hop mapping is easier to operate and less likely to create loops.
Once those checks pass, the dedicated redirect block provides a small, auditable boundary between the legacy host and the application that now owns the URL.
Quick Recap
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.




