A 301 is a permanent redirect, not a file-access error. First identify who sent it and where its Location points; then correct the matching NGINX server block, rewrite, file mapping, hotlink rule, or upstream application. Do not start by changing CORS headers: CORS affects browser access after a response, while a 301 changes the URL before the file is delivered.
Antihost offers Linux VPS plans with full root access, unlimited traffic on a 1 Gbps port and a 14-day free trial.
What a 301 means when another site requests your file
When a page on one site embeds an image, stylesheet, script, font, PDF, or download hosted by your NGINX server, the browser makes a separate request to the asset host. A 301 Moved Permanently response tells that browser to request a different URL. The destination is supplied in the Location response header.
As an Amazon Associate I earn from qualifying purchases.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →The redirect may be intentional, such as moving an old hostname to a new one. It may also be accidental: a catch-all canonical-host rule can intercept an asset request, a regex rewrite can alter a perfectly valid filename, a missing file can fall through to an application route, or a proxy can pass through a redirect generated by the application. A browser may then cache the permanent response, making a fixed server appear broken until you test with a fresh command-line request.
A request coming from another domain does not inherently cause NGINX to return 301. Cross-origin status is independent from the HTTP redirect status. Find the redirect source before editing configuration.
#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.
Diagnose the redirect before changing configuration
1. Capture every response header and redirect hop
Use a request for headers only and follow the chain:
curl -IL https://files.example.com/assets/app.css
Record the first status line and every Location value. Compare the original and destination URLs:
- A scheme change, such as HTTP to HTTPS, usually indicates TLS or canonical-scheme logic.
- A host change points to canonical-host or migration rules.
- A path change, such as adding a slash or changing a filename, points to a rewrite, directory normalization, or application route.
- Several 301 responses indicate a chain; a final 200 does not make the chain harmless because each hop adds latency and can break embedded assets.
Use curl -I without -L when you need to inspect only the first response. Following redirects can hide which server generated the initial status. Add -v when you need to see the request’s Host header, TLS negotiation, or connection reuse.
To avoid a browser’s cached permanent redirect, use a new URL only for testing, a separate client profile, or curl. A cached 301 can survive after the server configuration is corrected.
2. Inspect the active, merged NGINX configuration
Run this as an administrator on the machine serving the request:
nginx -T
This prints the configuration after included files are merged. Search the output for the requested hostname, listening address and port, and the asset path. Identify the selected server_name, exact and regular-expression location blocks, and each of these directives:
Free tools Windows power users keep installed
One-click scans. No signup required.
returnrewriteerror_pagerootoraliastry_filesproxy_pass
Do not rely on the file you remember editing. An included file, a default server, or a generated configuration may be the one NGINX actually loaded. After a change, validate it with nginx -t and reload NGINX using the service method appropriate to your operating system. Keep a copy of the known-good configuration so a broad redirect can be reverted quickly.
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.
3. Watch the error log during one request
Tail the relevant NGINX error log while issuing one curl request. A message about repeated internal redirects suggests a rewrite loop. An upstream status or proxy connection message suggests that an application, load balancer, or second NGINX instance generated the response. A missing-file message points to URI-to-filesystem mapping or permissions. Correlate the timestamp and request path; do not infer the cause from an unrelated log entry.
4. Test the local file independently
For a file that should be served by NGINX, check that the configured root or alias resolves the URI to the intended file and that the worker process can read every directory in the path. If the file exists but the request still redirects, add an explicit try_files fallback while testing so a miss cannot silently enter an application route.
5. Compare controlled request variants
Cross-site behavior can be reproduced without a browser. Test a request with no referrer, then send explicit values:
curl -I https://files.example.com/assets/app.css
curl -I -e https://www.example.com/page https://files.example.com/assets/app.css
curl -I -e https://unapproved.example/page https://files.example.com/assets/app.css
Also test the HTTP and HTTPS forms separately if both are enabled. If only one variant redirects, the difference is likely conditional policy or upstream logic rather than the file itself. A referrer header is optional and forgeable, so these tests show how the policy behaves, not who is genuinely sending the request.
How NGINX chooses the rule that returns 301
Canonical host and scheme redirects
NGINX selects a server block using the listening address, port, and Host header before it selects a location. A host-wide redirect in the default or canonical block can therefore catch requests intended for a separate asset hostname. A robust migration isolates the old hostname in its own server block and leaves the file-serving hostname in a block without that redirect:
server {
listen 80;
server_name old.example.com;
return 301 https://new.example.com$request_uri;
}
server {
listen 80;
server_name files.example.com;
root /srv/www/files;
location /assets/ {
try_files $uri =404;
}
}
Make the asset hostname explicit in DNS and in server_name. If both names must serve files, give each a deliberate policy; do not depend on whichever block happens to be the default for that port. Check both IPv4 and IPv6 listeners when the two addresses use different configurations.
return versus rewrite
Use return for a simple, fixed redirect in the narrowest matching server or location context. It stops processing and sends the chosen status and URL immediately. For example:
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsRank #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
location = /old-manual.pdf {
return 301 https://files.example.com/manual.pdf;
}
Use rewrite when a pattern-based transformation is genuinely required. A rule ending in permanent sends a 301 to the client; it is not an internal filesystem mapping. A rule with last starts a new location search, while break continues in the current location. Choose deliberately:
location /legacy/ {
rewrite ^/legacy/(.*)$ /downloads/$1 last;
}
A rewrite that sends a request back into a location containing the same rewrite can loop. NGINX limits repeated rewrite processing to ten cycles and can return 500 after that limit. Simplify overlapping patterns, anchor regular expressions, and use break when a new location search is not needed. Test a path that should match and a nearby path that should not, because an unanchored expression can redirect unrelated assets.
root, alias, and try_files
root appends the request URI to a directory. For root /srv/www/files;, a request for /assets/app.css maps to /srv/www/files/assets/app.css. An alias replaces the matching location prefix instead, so its trailing-slash form and location path must be chosen carefully.
For example, location /assets/ { alias /srv/static/; } maps /assets/app.css to /srv/static/app.css, not to a nested assets directory. A missing or mismatched trailing slash can produce unexpected paths and make a valid file look absent. Confirm the resolved path on disk rather than guessing from the URL.
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 →try_files checks candidate files or directories. It can serve a local file, internally redirect to another URI or named location, or return an explicit status. For a static asset location, an explicit 404 is safer than silently handing a miss to a front controller:
location /assets/ {
root /srv/www/files;
try_files $uri =404;
}
If the final argument is an application URI or named location, a missing file may reach code that issues a 301. Temporarily changing the fallback to =404 distinguishes a missing mapping from a redirect generated downstream. Query strings do not change the filesystem lookup, but verify how an application or redirect preserves them in the returned Location.
error_page mappings
An error_page directive can convert an error into an internal URI or an external redirect. Review mappings for 404, 403, and 500 responses. If the desired behavior for an absent asset is a hard 404, remove an accidental redirect mapping or use an explicit status in the asset location. Test both an existing file and a deliberately nonexistent filename.
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.
Upstream applications and proxy chains
A proxied application can generate the 301, even when the visible NGINX file contains no redirect. Compare the response from the public URL with a request to the local static-file path or the upstream service, using an internal address and appropriate Host header where applicable. If the upstream sends Location, fix its base URL, trusted-proxy scheme handling, route, or canonical-host setting rather than adding another NGINX rewrite. Avoid creating a redirect chain between the proxy and application.
Recommended Free Tools
Fix an asset hostname that is caught by a site-wide redirect
- Confirm the request’s
Hostvalue withcurl -Iand note the destination host inLocation. - In
nginx -T, find every server block listening on the requested port and the block that matches the asset hostname. - Move the migration redirect into a server block whose
server_namecontains only the old hostname. - Create or correct a dedicated asset block with the intended
root, narrowlocation, andtry_files $uri =404. - Run
nginx -t, reload, and repeatcurl -IL. The expected result for an existing file is normally 200 (or a deliberate non-redirect response), not a 301.
Fix a filename rewrite that should have been a local file lookup
Search for rewrite rules matching the extension or directory. If a rule ends in permanent but the goal is to find a file on disk, replace it with a correct root/alias mapping and try_files. Keep a redirect only when clients really must learn a new public URL.
Test names containing dots, hyphens, query strings, and URL-encoded characters. Query strings normally remain attached to a redirect unless a replacement URI changes them; verify the actual Location rather than assuming. Check both the exact asset path and a nearby path that should not match the regex, because an overly broad expression can redirect unrelated resources.
Handle hotlink protection without mistaking it for authentication
Referer-based controls inspect the HTTP Referer header. NGINX’s valid_referers directive sets the $invalid_referer variable, which can be used to deny requests from unapproved pages. A narrow illustrative policy is:
location ~* .(gif|jpe?g|png|webp|css|js|pdf)$ {
valid_referers none blocked server_names *.example.com;
if ($invalid_referer) { return 403; }
try_files $uri =404;
}
Adapt the extensions and allowed hostnames to your site. This example returns 403, not 301, so it does not explain a redirect unless another rule handles the denied request. Browsers can omit Referer because of privacy settings, referrer policies, HTTPS-to-HTTP transitions, extensions, or direct navigation. Non-browser clients can also forge it. Treat this mechanism as traffic control, not proof of identity or access authentication.
Test three cases: no Referer, an allowed referring URL, and a disallowed referring URL. If only one case redirects, inspect the complete location and any conditional rewrite or error handling around the hotlink rule. Do not assume that a cross-domain request is malicious simply because its header differs.
Common failure modes and precise remedies
| Symptom | Likely cause | Remedy |
|---|---|---|
| Every asset redirects to the main website | Canonical redirect in a default or broad server block | Separate old-host and asset-host server_name blocks; remove the broad match. |
| Only missing assets return 301 | try_files falls through to an application or named location |
Use try_files $uri =404 while diagnosing and fix the file path or upstream route. |
| A filename changes unexpectedly | rewrite ... permanent or a trailing-slash rule |
Remove the pattern from the asset location or replace it with a deliberate internal mapping. |
| Redirect appears after a 404 or 403 condition | error_page maps the status to a redirect URI |
Inspect and remove the mapping, or return the intended status directly. |
| Logs show repeated internal redirects | Rewrite rules bounce between locations | Anchor patterns, reduce overlapping rules, and use break when another location search is unnecessary. |
| NGINX configuration has no matching redirect | Proxied application or another proxy layer generated it | Compare upstream headers with the local static path and correct the application’s canonical URL settings. |
| Browser still redirects after the fix | Cached permanent response | Verify with curl and a fresh client; clear the affected browser or intermediary cache after the server response is correct. |
Permissions and filesystem checks
When a URI should be local, verify the complete resolved path, not merely the filename. The NGINX worker account needs execute permission on each parent directory and read permission on the file. A wrong ownership or mode can produce a 403, which an error_page rule may then turn into a redirect. Check symbolic links, mount availability, case sensitivity, and mandatory access-control policies on the host. Keep filesystem diagnostics separate from redirect diagnostics: first establish whether NGINX found the file, then decide how an error should be represented.
Best Value
A repeatable repair workflow
- Run
curl -ILagainst the exact public asset URL and save the headers. - Classify the
Locationchange as scheme, host, path, or slash normalization. - Run
nginx -T; identify the selected server and location plus all redirect-capable directives. - Make one request while watching the error log and determine whether an upstream participated.
- For local files, verify
root/alias, permissions, and an explicittry_files $uri =404fallback. - For intentional migrations, keep a fixed
return 301in the old-host block only. - For pattern changes, simplify
rewriterules and selectlastorbreakintentionally. - For hotlink policies, test absent, allowed, and disallowed
Referervalues and use 403 for denial unless a redirect is truly intended. - Run
nginx -t, reload, retest all redirect hops, and then test from a clean client.
Change one layer at a time. First prove that the public request reaches the intended server block, then prove that the URI maps to the intended file, and only afterward re-enable application fallbacks or referrer restrictions. This order prevents a new rewrite from masking a permissions problem and makes rollback straightforward.
What the final response should look like
An existing static file on its intended hostname should resolve to a single, predictable response, commonly 200, with no unnecessary host or path change. A deliberately moved file may return one 301 to its permanent public URL. A missing file should return the status your policy specifies, usually 404, rather than being redirected into an unrelated application page. Keeping those outcomes distinct makes cross-site embeds reliable and makes future failures visible in logs instead of hiding them behind a redirect chain.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Frequently Asked Questions
Why does NGINX return a 301 when another website requests my image or CSS file?
The referring website is not itself a reason for a 301. A matching canonical-host or HTTPS rule, filename rewrite, error_page mapping, fallback application, or upstream proxy usually generated it. Inspect the first Location header and the active configuration to identify which layer responded.
How can I tell whether the redirect comes from NGINX or my application?
Run nginx -T and inspect return, rewrite, error_page, try_files, and proxy_pass directives. Then compare the public response with a direct request to the local static path or upstream service. If the upstream response already contains Location, correct the application’s canonical URL or trusted-proxy settings.
What should a missing static file return instead of a redirect?
Use an explicit try_files $uri =404 fallback in the asset location while diagnosing. This prevents a missing file from falling through to a front controller that may issue a 301. Keep a different response only when your application policy deliberately requires it.
Can hotlink protection create a 301?
The valid_referers example normally denies an invalid referrer with 403, not 301. A redirect can still appear if another conditional rule or error_page mapping handles that denial. Test requests with no, allowed, and disallowed Referer headers, and remember that the header is optional and forgeable.
Why does the browser keep redirecting after I fixed NGINX?
Browsers and intermediaries can cache permanent redirects. Verify the current response with curl -IL or a fresh client, then clear the affected browser or intermediary cache. Make sure every Location hop is gone rather than checking only the final 200 response.
Should I use return or rewrite for an NGINX redirect?
Use return for a simple fixed destination in the narrowest matching server or location. Use rewrite for a deliberate pattern transformation, choosing last when NGINX should search locations again and break when it should continue in the current location. Avoid rules that send the request back through themselves.
The Bottom Line
Trace the first 301 with curl -IL, inspect the merged configuration with nginx -T, and watch the error log. Isolate canonical redirects by hostname, serve local assets with correct root/alias and try_files, inspect error_page and upstream responses, and treat Referer-based hotlink controls as traffic policy rather than authentication.
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.




