Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
VGSOURCES
Get listed

NGINXPATCH 2026.10.16

How to Use Nginx Location Alias With Rails

By VGSources Team 12 min read

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

Use an Nginx alias location when the URL prefix should map to a specific directory, such as mapping /assets/ to a Rails release’s public/assets/. Use root when the requested URI should be appended to one document-root directory. In a normal Rails deployment, Nginx serves fingerprinted files from public/assets and proxies every other request to Rails.

The mapping you need to understand

Nginx handles root and alias differently. A root keeps the complete request URI and appends it to the configured directory. An alias replaces the part of the URI matched by the location with the alias path.

As an Amazon Associate I earn from qualifying purchases.

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

For a request to /assets/application-abc123.css, these configurations produce the same filesystem path when the directory layout mirrors the URL:

location /assets/ {
    root /srv/myapp/current/public;
}

Nginx resolves that request as /srv/myapp/current/public/assets/application-abc123.css.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses | Anti UV Ray, For Computers & Gaming, Square Frame, Eyewear for Men and Women
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.
location /assets/ {
    alias /srv/myapp/current/public/assets/;
}

Here Nginx replaces the matched /assets/ prefix with /srv/myapp/current/public/assets/, producing the same path. The difference becomes important when the names do not mirror one another. For example, /downloads/guide.pdf can map to /srv/myapp/shared/uploads/guide.pdf with alias; a root configuration would normally look for an uploads directory beneath the root only if the URI and directory structure were arranged that way.

A production configuration for Rails assets

This pattern gives Nginx a narrow public location for compiled assets and sends dynamic requests to Rails:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
upstream rails_app {
    server 127.0.0.1:3000;
}

server {
    listen 80;
    server_name example.com;

    location /assets/ {
        alias /srv/myapp/current/public/assets/;
        expires 1y;
        add_header Cache-Control public;
        add_header ETag "";
    }

    location / {
        proxy_pass http://rails_app;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

The trailing slash on both location /assets/ and the alias directory makes the replacement unambiguous. A request for /assets/application-abc123.css maps to /srv/myapp/current/public/assets/application-abc123.css. Replace the example release path, hostname and upstream port with values from your deployment, then verify the resulting path on disk.

The catch-all location / is not a second asset server. It proxies routes such as pages, API requests, authentication and other responses that Rails must generate. Keep the alias limited to files intended for unrestricted public delivery.

Prepare Rails before configuring Nginx

Rails production assets are normally compiled into public/assets. Source files elsewhere in the application do not satisfy an Nginx alias; Nginx can only return a file that exists at the exact resolved path.

  1. Build or select the release directory that Nginx will serve. In the example, that is /srv/myapp/current.
  2. Run the production precompile task from that release. Rails documents this command for a build that uses a temporary secret during compilation:
    RAILS_ENV=production SECRET_KEY_BASE_DUMMY=1 rails assets:precompile
  3. Confirm that fingerprinted files, such as application-abc123.css or application-abc123.js, exist beneath /srv/myapp/current/public/assets/.
  4. Deploy the release and update the current symlink, or otherwise make sure the alias points to the same release that generated the HTML references.

Fingerprinting is significant. Rails pages refer to the digest filename produced by the current build. If the page asks for a digest that is absent from the release Nginx is reading, the response is a 404 even when an older or undigested source file exists elsewhere.

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

Choosing between root and alias

Question root alias
How is the path formed? Nginx appends the complete request URI to the root directory. Nginx replaces the URI portion matched by the location with the alias target.
Best fit The URL hierarchy mirrors directories beneath one document root. The URL prefix and filesystem directory have different names or must be replaced explicitly.
Example for /assets/file.css /srv/myapp/current/public becomes /srv/myapp/current/public/assets/file.css. /srv/myapp/current/public/assets/ replaces /assets/.
Trailing slash concern Still important for predictable directory behavior, but URI appending is the defining rule. Keep the prefix and target directory’s trailing slashes aligned when mapping a directory.
Non-mirroring example Requires a root layout that reflects the URL. /downloads/ can map directly to /srv/myapp/shared/uploads/.

Neither directive makes a private file safe. Both can expose any readable file in the selected public location, so authorization requirements must be considered separately.

Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed

How Nginx selects the location

Nginx evaluates prefix and regular-expression locations in a defined order. It first finds the longest matching prefix, then considers regular-expression locations according to its location rules. A specific /assets/ prefix can therefore coexist with a general / proxy, but another regular-expression block may intercept an asset request if the server configuration allows it.

Keep the asset block narrowly scoped and inspect the complete active configuration, not only the file you edited. A broad regex for extensions, a nested location, or an included configuration file can change which block handles a request. If an assets location must take precedence over regular expressions, review whether the appropriate prefix modifier is needed for your configuration and test the result rather than assuming it.

Do not put authentication, Rails routing or an unrestricted filesystem alias in the same conceptual path. Public static delivery and application-controlled responses have different security and caching requirements.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

Use try_files when a fallback is required

An alias is sufficient when every referenced asset must exist and a missing file should simply return 404. Add try_files when you need Nginx to check candidates or send misses to a controlled fallback.

location /assets/ {
    alias /srv/myapp/current/public/assets/;
    try_files $uri =404;
    expires 1y;
    add_header Cache-Control public;
}

Nginx evaluates try_files using the active root or alias. If a candidate exists, Nginx serves it or internally redirects as configured; if none exists, a final status such as =404 ends the request. Use a Rails fallback only when that behavior is intentional. Sending every typo to the application can hide deployment errors and add avoidable load.

Cache headers for fingerprinted files

Rails documents a one-year Nginx cache example for precompiled assets:

location ~ ^/assets/ {
    expires 1y;
    add_header Cache-Control public;
    add_header ETag "";
}

Fingerprinting makes long-lived caching practical because a changed file receives a new URL. The exact header arrangement should match your cache policy and the rest of the server configuration. If you use the prefix-and-alias configuration, put the cache directives in that location and confirm that no later or more specific block overrides them.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men | Office Gifts for Women, iPhone Stand, Gadgets for Men, Office Decor, Gaming Desk Accessories for Samsung Fold 8, Switch, iPad
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

The example clears the ETag header with add_header ETag "". Treat that as a deliberate policy choice, not a requirement for every installation. Check the response headers with a request for an actual fingerprinted file before relying on browser or intermediary-cache behavior.

Deployments and changing release directories

Release-based Rails deployments commonly create a new directory for each build and move a current symlink. An alias that points to a dated release can continue serving old files after Rails starts generating references from a new release. An alias that points to current/public/assets/ follows the symlink, but the transition still needs to be atomic and tested.

  • Precompile assets inside the release that will become current.
  • Verify permissions and file presence before switching traffic.
  • Switch the release pointer only after the compiled files and application code are complete.
  • Reload Nginx only when a configuration change requires it; a symlink switch alone does not necessarily require a reload.
  • Retain old releases until cached HTML or in-flight requests no longer depend on their digest files, according to your deployment policy.

If the HTML and static files come from different releases during a non-atomic deploy, users can see intermittent 404 responses. A consistent release pointer and a rollback plan are more reliable than copying assets into a shared directory without tracking which build produced them.

Permissions and filesystem checks

Nginx workers need permission to traverse every parent directory and read the target file. A file can exist and still return 404 or a permission-related error if the worker user cannot access /srv, /srv/myapp, the release directory, or public/assets.

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

Check the effective worker account, directory execute permissions and file read permissions. Avoid solving a deployment problem by making the entire application tree world-readable. Grant access to the narrow public directory and keep secrets, source configuration and private uploads outside it.

Private files require Rails authorization

A public alias is the wrong design for invoices, paid downloads, user uploads or any file whose access depends on a Rails decision. Anyone who can construct the URL could request a file directly, bypassing controller authorization.

Rails documents Nginx integration with:

config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'

With this pattern, the request reaches Rails first. Rails authenticates the user and authorizes the specific file, then returns an internal redirect header that tells Nginx to transfer an approved file. The storage directory is not exposed as an unrestricted public location. Configure the corresponding internal Nginx location and ensure the path Rails emits matches that internal mapping; do not combine it with a public alias for the same private directory.

Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC

Validation before and after reload

  1. Confirm the generated URL in the Rails page, including its fingerprint.
  2. Resolve that URL manually against the alias directory and verify the file exists.
  3. Check that the Nginx worker can traverse each parent directory and read the file.
  4. Run nginx -t and correct every reported syntax or include-file error before reloading.
  5. Reload Nginx using your operating system’s service procedure.
  6. Request the asset directly and inspect the status, headers and body. A successful static response should not pass through the Rails upstream.
  7. Review access and error logs while making a request. Logs distinguish a location mismatch, missing file, permission failure and upstream response.

Test both a known-good fingerprinted file and a deliberately missing filename. The first confirms mapping and permissions; the second confirms that your intended 404 or fallback behavior is actually in force.

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

Understanding the resolved path in practice

When diagnosing an alias, write the substitution out literally. Remove the matched location prefix from the request URI, then append the remainder to the alias directory. For /assets/images/logo.svg and alias /srv/myapp/current/public/assets/, the remainder is images/logo.svg, so the expected file is /srv/myapp/current/public/assets/images/logo.svg. This simple calculation catches accidental mappings to public/assets/assets, a shared directory, or an old release.

Do the same exercise for a non-mirroring path. With location /downloads/ and alias /srv/myapp/shared/uploads/, /downloads/guide.pdf should resolve to /srv/myapp/shared/uploads/guide.pdf. If your intended path still contains downloads, root may better express the layout, or the alias target is not the directory you meant to publish.

Further location and fallback checks

Do not assume that the file extension determines the serving block. Nginx first identifies the relevant prefix and then applies its regular-expression location rules. Review included virtual-host files, extension regexes and nested locations together. A request that unexpectedly reaches Rails is evidence that the active configuration differs from the simplified snippet, not that Rails has failed to compile the asset.

Use a hard =404 for immutable assets when a missing digest indicates a bad deploy. A fallback to Rails is appropriate only when the application is designed to generate or locate that response. Otherwise, every miss can consume an application worker and conceal a broken release.

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

Troubleshooting Rails asset 404s

Symptom Likely cause What to check
Every asset returns 404 The alias directory is wrong, empty or not readable. Compare the resolved filesystem path with the active release and inspect permissions.
Only newly deployed assets fail Nginx still points at an older release, or precompilation was skipped. Check the current symlink, release contents and the output of the production precompile task.
The request reaches Rails instead of Nginx A different location wins. Inspect regex and prefix locations in the full configuration and review the access log.
Paths contain duplicated or missing directory names The location and alias slash conventions do not express the intended replacement. Use location /assets/ with alias .../public/assets/ for this directory mapping.
Public users can retrieve protected uploads A private directory was exposed through an alias. Remove the public location and use Rails authorization with X-Accel-Redirect.
Old CSS or JavaScript persists Cache headers or release retention do not match the deployment strategy. Inspect response headers and confirm that each build produces a new digest URL.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common configuration mistakes

Using root when the directory does not mirror the URI

Putting root /srv/myapp/shared/uploads; inside location /downloads/ does not mean that /downloads/file.pdf automatically becomes /srv/myapp/shared/uploads/file.pdf; Nginx appends the URI according to root semantics. If the URL prefix should disappear, use an alias whose target explicitly represents the replacement.

Pointing at Rails source instead of compiled output

Nginx does not run the asset pipeline. It cannot compile Sass, resolve Rails helpers or discover a source file outside the alias directory. Run the production precompile task and point the alias at the resulting public/assets directory.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

Leaving the trailing slash implicit

Directory aliases are easiest to audit when both the matched prefix and target directory end in a slash. A missing slash can make the resulting path differ from the one you intended, especially when the location is changed later or combined with another directive.

Exposing the whole application release

Do not set an alias to /srv/myapp/current/ merely to make one missing asset appear. That can expose source code, logs, configuration and other files. Alias only the public directory that must be downloadable.

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

Decision checklist

  • Does the URL prefix mirror a directory beneath one document root? If yes, root may be clearer.
  • Must a prefix such as /downloads/ map to a differently named directory? Use alias.
  • Are the files Rails-produced, fingerprinted and precompiled in the active release? If not, fix the build before changing Nginx.
  • Should a missing file be a hard 404, a candidate lookup or an application fallback? Choose try_files behavior explicitly.
  • Are the files public? If access depends on a user or subscription, use Rails authorization and X-Accel-Redirect, not a public alias.
  • Will the release path change during deployment? Point at a controlled current path and switch releases atomically.

Final configuration model

For the usual Rails case, compile assets into the release’s public/assets, map the exact /assets/ prefix to that directory with a trailing-slash alias, apply a cache policy appropriate for fingerprinted files, and proxy all other requests to Rails. Use root only when appending the full URI is the behavior you want. Before reload, verify the active location, the resolved path, permissions, release contents and logs; for private files, remove the public alias and let Rails authorize an internal Nginx transfer.

Frequently Asked Questions

Should Rails assets use Nginx root or alias?

Use alias when /assets/ must be replaced by a specific directory. Use root when the complete URI should be appended beneath a document root and the directory layout mirrors the URL.

Why do Rails assets return 404 behind Nginx?

Common causes are skipped precompilation, an alias pointing at the wrong or old release, missing trailing-slash alignment, location precedence selecting another block, or permissions that prevent the worker from traversing and reading the file.

How do I serve Rails public/assets directly?

Run RAILS_ENV=production SECRET_KEY_BASE_DUMMY=1 rails assets:precompile, point location /assets/ at the release’s public/assets/ with alias, and proxy the general location / to Rails.

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

Do I need try_files with an alias?

No. Add try_files when you need candidate checks or an explicit fallback. For immutable fingerprinted assets, try_files $uri =404; makes a missing file a clear hard 404.

Can an alias protect private uploads?

No. A public alias allows direct URL access to readable files. Keep authorization in Rails and use X-Accel-Redirect with an internal Nginx location for approved downloads.

Do I have to reload Nginx after switching the current symlink?

A symlink switch alone does not necessarily require a reload. Reload when configuration changes, and test the new release, permissions and asset URLs before directing traffic to it.

The Bottom Line

Precompile Rails assets into the active release, map /assets/ to public/assets/ with a matching trailing-slash alias, cache fingerprinted files appropriately, and proxy everything else to Rails. Choose root only when URI appending matches your directory layout; keep private files behind Rails authorization and X-Accel-Redirect.

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

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.

NGINXNginx aliasRailsRails assetsweb deployment

Leave a reply

Your email address will not be published. Required fields are marked *

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

Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.