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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

If NGINX returns 301 Moved Permanently when another site requests an image, stylesheet, script, PDF, or other file, first find the redirect target. The response may come from a canonical-host rule, a URI rewrite, an error_page mapping, a proxy application, or a hotlink policy—not from cross-domain access itself.

Run curl -IL https://files.example.com/assets/app.css, record every Location header, inspect the active configuration with nginx -T, and watch the error log during one test request. Once you know which layer creates the 301, narrow or remove that rule, or configure the static-file location to return the file (or an explicit 404) instead of redirecting.

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

What a 301 means in this situation

A 301 is an HTTP response telling the client that the requested URI has been permanently moved. NGINX normally includes a Location header containing the next URL. A browser, crawler, or embedding website then decides whether to request that URL. The redirect can change the scheme, hostname, path, or only the trailing slash.

Cross-site delivery does not inherently require a redirect. A file hosted at files.example.com can be requested by a page on another origin and receive a normal 200, subject to any access policy and, for browser-readable resources, the appropriate CORS headers. A 301 is a routing decision made by NGINX or an upstream application. Treat it separately from CORS, DNS, and file permissions.

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application: attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Economical &Reusable: Built durable materials with a long-lasting battery,our CAGIWIRU air duster it's a sustainable alternative to disposable air cans.

Do not assume that the asset location caused the response. NGINX selects a server block from the listen address and requested host, then chooses a matching location. A broad return 301 in the selected server block can run before the request reaches the location intended to serve the file. Likewise, a local file lookup can fall through to a proxy that emits its own redirect.

Identify the redirect before editing configuration

  1. Request headers and follow the complete chain. Use curl -IL https://files.example.com/assets/app.css. The first response shows the server’s immediate behavior; subsequent responses show what the client reaches after following each Location. If you need to prevent curl from following redirects while inspecting only the first response, use curl -I https://files.example.com/assets/app.css.
  2. Record each status and location. Note whether the first 301 changes http to https, changes the host, adds or removes a slash, changes the file path, or points to an application route. A redirect to a different hostname usually indicates canonical-host logic; a changed path or slash often indicates a rewrite or directory normalization.
  3. Dump the merged configuration. As an administrator, run nginx -T. This prints included files after they have been combined, which is more reliable than opening one suspected configuration file. Find the relevant listen, server_name, exact or regular-expression location, return, rewrite, error_page, try_files, root, alias, and proxy_pass directives.
  4. Watch the error log while making one request. Use the log configured for the selected server and issue a single curl request. Messages about repeated internal redirects suggest a rewrite or fallback loop. An upstream status or connection entry points toward a proxied application rather than a static-file rule. A quiet log does not prove that no redirect exists; many deliberate return directives are not errors.
  5. Verify the filesystem mapping. For a locally served file, calculate the path produced by root or alias, confirm that the file exists there, and verify that the NGINX worker can traverse its directories and read it. A missing or unreadable file can trigger a fallback route that redirects.
  6. Repeat the request with relevant headers. Test without a Referer, with a permitted referring site, and with a deliberately disallowed referring site. Compare the status and Location values. Differences indicate policy behavior, but they do not authenticate the caller because the Referer header is optional and can be forged.

Make sure the request reaches the intended server block

NGINX chooses a server block using the address and port from listen and the hostname in the request’s Host header (or the TLS name for HTTPS). If no server_name matches, the default server for that address and port handles the request. A generic default block that redirects every request to a main website can therefore catch an asset hostname accidentally.

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

Check for overlapping names, a missing asset hostname, and separate HTTP and HTTPS blocks that do not contain equivalent locations. Test both the public hostname and the address you expect NGINX to use. When a load balancer or CDN is in front, make sure the request is actually reaching the NGINX instance whose configuration you inspected; otherwise you may be changing the wrong layer.

For a hostname migration, keep the redirecting old host separate from the host that serves files. This prevents a host-wide redirect from swallowing the static location:

Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth
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;
    }
}

The first block has one job: redirect requests addressed to the old hostname. The second block maps requests for files.example.com to local files and returns a hard 404 when a file is absent. Create equivalent HTTPS blocks when the asset hostname is served over TLS, and test the exact scheme and hostname used by the embedding page.

Serve local files with root, alias, and try_files

The root directive appends the request URI to a filesystem directory. With root /srv/www/files, a request for /assets/app.css maps to /srv/www/files/assets/app.css. The mapping is not a redirect; NGINX reads the file and returns it when the file exists.

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

alias replaces the matching location prefix instead of appending the entire URI. Because a missing or misplaced trailing slash can map to an unexpected path, use it only when you have deliberately checked the resulting filename. If you do not need a different directory layout, root is usually easier to reason about.

try_files checks candidate files or directories in order. A typical static location is:

Rank #3
Sale
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black | LED mouse pad with 14 lighting modes, covers keyboard & mouse, anti-slip rubber base, waterproof surface, USB powered
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.
location /assets/ {
    try_files $uri =404;
}

When the requested file exists, NGINX serves it. When it does not, =404 ends the lookup with an explicit 404 rather than sending the request to an application or named location. That explicit fallback is useful while diagnosing a 301 because it distinguishes “the file is missing” from “another component redirected the fallback.”

A different final argument can intentionally perform an internal redirect, for example to an application route. That behavior is useful for front-controller applications but can hide the origin of an asset redirect. Temporarily use an explicit status while testing, then restore the application fallback only if it is actually required.

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

Choose return or rewrite for the rule you need

Use return for one fixed destination

return stops request processing immediately and sends the chosen status and, for a redirect, the specified URL. It is the clearest option for a fixed host migration or a narrowly scoped location:

server {
    listen 80;
    server_name old.example.com;
    return 301 https://new.example.com$request_uri;
}

Put a fixed redirect in the narrowest server or location context that should receive it. A host-wide return in the canonical asset server is a common reason that images or scripts never reach their file location.

Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.

Use rewrite for deliberate pattern transformations

rewrite is intended for pattern-based URI changes. Its directives run sequentially, and flags determine what happens next. last starts a new location search with the rewritten URI; break stops rewrite processing in the current location without starting that new search. A redirect flag such as permanent sends a 301 to the client.

Do not use a permanent rewrite when you meant to map a URI internally to a local file. Replace it with the appropriate root/alias and try_files logic, or with a narrowly scoped return if an external move is genuinely intended. Avoid rules that rewrite a URI back into the same pattern or bounce between locations. NGINX limits rewrite processing to ten cycles; repeated processing can end in a 500 response instead of a useful file response.

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

Check fallbacks, error_page, and proxying

A static request can become a redirect even when no redirect appears in its visible location. Three paths deserve particular attention:

  • try_files fallback: If the file is absent, the final argument may send the request to a named location or application route. That target can return a 301. Temporarily change the fallback to =404 to prove whether the redirect is downstream.
  • error_page mapping: An error_page directive can convert an error into an internal redirect or an external redirect. Search the complete configuration for mappings that apply to 404, 403, or other statuses. Remove an unintended redirect mapping or use an explicit status when the desired behavior is a hard 404.
  • proxy_pass or another upstream: A proxied application may issue the 301 because it believes the public URL uses a different scheme, host, or slash form. NGINX can pass that response to the client, making the redirect look like an NGINX rule.

Compare the local static path with the upstream path. First request the file through the public NGINX URL. Then, from an authorized administrative environment, request the upstream endpoint directly with the same relevant host and scheme headers. If the upstream returns the 301 directly, correct its base URL, trusted proxy settings, or route; do not add another NGINX rewrite to mask it. If the upstream is correct but the public request redirects, return to server and location selection.

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Handle hotlink protection without mistaking it for authentication

Referer-based hotlink controls inspect the HTTP Referer header. NGINX’s valid_referers directive defines accepted values and sets $invalid_referer when the value is absent or does not match the policy. A narrow asset location can reject disallowed requests:

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, because denial is clearer than silently sending another site to a different URL. If your existing policy returns a 301, inspect that rule and decide whether an explicit 403 or a normal file response better matches the intended behavior.

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

Referer is traffic-control metadata, not proof of identity. Privacy settings, security software, redirects, and browser policies can omit it for legitimate users. Any client can also fabricate it. Allowing none and blocked may be appropriate for direct requests, but make that choice deliberately. Do not use this mechanism to protect confidential downloads; use real authentication and authorization for that purpose.

Test cross-site behavior accurately

Use curl to separate server behavior from browser state. A minimal sequence is:

curl -I https://files.example.com/assets/app.css
curl -IL https://files.example.com/assets/app.css
curl -I -e https://allowed.example/ https://files.example.com/assets/app.css
curl -I -e https://untrusted.example/ https://files.example.com/assets/app.css

The -e option supplies a test Referer. To model a request with no Referer, omit the option. Compare the first status, all Location values, and any policy-specific differences. Include an Origin header only when you are testing CORS behavior; it does not itself explain a 301.

Browsers cache permanent redirects aggressively. A browser may continue following an old 301 after the server has been corrected. Verify the current response with curl, then use a fresh private window or clear the relevant site data before judging the browser result. A service worker, CDN, reverse proxy, or corporate cache can also retain the old response, so purge or bypass those layers when applicable.

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

Common failure patterns and targeted fixes

Observed behavior Likely source Targeted action
Every asset hostname request goes to the main website A return or rewrite in the default or canonical server block Add an explicit server_name for the asset host and isolate the migration redirect in a separate block.
The file path changes to a slash-normalized or different URI A pattern rewrite or directory redirect Inspect rewrite order and flags; use try_files for local files and keep only the normalization that is required.
Existing files work, missing files become 301s try_files falls through to an application or named location Test with try_files $uri =404;, then inspect the fallback route before restoring it.
A missing asset becomes a redirected error page error_page mapping Remove the external redirect mapping or return the intended error status explicitly.
Logs show repeated internal redirects or a final 500 Rewrite rules cycling between locations Simplify the chain, check the rewritten URI against every location, and use break when a new location search is not intended.
Only requests from some pages redirect or fail Referer-dependent hotlink policy or a cached browser response Test with absent, allowed, and disallowed Referer values; then clear caches and revise the policy status.
Direct local testing is correct but public requests redirect Upstream application, load balancer, CDN, or a different NGINX instance Compare upstream headers and confirm which server handled the public request before editing rules.

Validate and deploy the correction safely

  1. Save a copy of the current configuration and change only the suspected directive or server block.
  2. Run nginx -t to validate syntax and referenced files. Do not reload a configuration that fails this check.
  3. Reload NGINX using your operating system’s service manager after a successful test. A reload applies the new configuration without unnecessarily stopping workers.
  4. Repeat the exact curl commands, including the cross-site Referer variants that reproduced the issue. Confirm the expected status and that no unwanted Location header remains.
  5. Check the error log for one request and verify that the intended file path, not an application fallback, handled it.
  6. Test a missing file, an allowed asset request, and a request to the old hostname. Each should produce the policy you chose: normally a 200, an explicit 404 or 403, or an intentional migration 301.

If you cannot access server blocks, merged configuration, or logs, the practical fix requires whoever administers the NGINX or upstream service. A managed NGINX host or a VPS with NGINX access can provide that control; changing HTML, adding a browser redirect, or repeatedly clearing cache cannot remove a server-side 301.

Configuration checklist

  • The requested hostname appears in the correct server_name block for the port and TLS name.
  • Canonical-host redirects are isolated from the server that serves the asset hostname.
  • The root or alias path resolves the URI to the intended file, with readable permissions.
  • The static location uses try_files and an explicit status when a missing file must not enter an application route.
  • Every return, rewrite, and error_page affecting the URI has been inspected in the output of nginx -T.
  • Any proxy_pass fallback has been tested separately so an upstream 301 is not mistaken for an NGINX-generated one.
  • Hotlink rules are narrow, return an intentional status, and are not treated as authentication.
  • Tests cover scheme, host, path, trailing slash, Referer presence, and cached-client effects.

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.