Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8822131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:01:38+00:00 2026-06-14T06:01:38+00:00

Is it possible to tell nginx an alternative location where to look when given

  • 0

Is it possible to tell nginx an alternative location where to look when given path does not exist? I’d like to serve static assets from my Rails application, however sometimes the compiled asset might not be available and I’d like to have a fallback.

production.rb

  # Disable Rails's static asset server (Apache or nginx will already do this)
  config.serve_static_assets = false

nginx.conf:

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

UPDATE:
nginx.conf

  #cache server
  server {
        listen 80;

        # serving compressed assets
        location ~ ^/(assets)/  {
                root /var/app/current/public;
                gzip_static on; # to serve pre-gzipped version
                expires max;
                add_header Cache-Control public;
                add_header ETag "";
        }

        try_files $uri /maintenance.html @cache;

        location @cache {
            proxy_redirect off;
            proxy_pass_header Cookie;
            proxy_ignore_headers Set-Cookie;
            proxy_hide_header Set-Cookie;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_cache one;
            proxy_cache_key app$request_uri;
            proxy_cache_valid 200 302  5s;
            proxy_cache_valid 404      1m;
            proxy_pass http://127.0.0.1:81;
        }
  }

  #real rails backend
  server {
        listen 81;
        root /var/app/current/public;
        error_log /var/app/current/log/error.log;

        rails_env production;
        passenger_enabled on;
        passenger_use_global_queue on;
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:01:41+00:00Added an answer on June 14, 2026 at 6:01 am

    yes with the try files directive:

    # note: you don't need the overhead of regexes for this location
    location /assets/ {
       try_files $uri /alternative_to_try
       # ... add back in rest of your assetts config
    }
    

    this will try the requested url and if not found try the alternative uri (you can also add a 3th, 4th, … option)

    Note that /alternative uri can be a named location (with for instance the directives for passing the url to the rails app)

    see http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files for more details and some examples regarding try_files

    update:

    right so change your assets’ location to

    location /assets/  {
       try_files $uri @cache;
       root /var/app/current/public;
       gzip_static on; # to serve pre-gzipped version
       expires max;
       add_header Cache-Control public;
       add_header ETag "";
    }
    

    in other words for all url’s where the part starts with /assets/:

    1. check if there’s an actual file corresponding to the path (that’s the $uri part of the try_files directive)
    2. if not, pass the request on to the named location @cache (that’s the @cache part of the try_files directive)
    3. if we get to the @cache location, it will first check the proxy cache zone one for a match
    4. if no cache match is found it will reverse proxy the request to the rails app at http://127.0.0.1:81
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand that it is not possible to tell what the user is doing
Is it possible to tell the C preprocessor to check whether a function (not
It seems that nginx does not support chunked requests well. But I'm trying to
Is it possible to tell VS not to recompile some projects every time and
Is it possible to tell the Qt MOC that I would like to declare
Is it possible to tell pyparsing to not store ParseResults or manually discard them?
Is it possible to tell a link not to change color in CSS and
Is it possible to tell gcc to show all warnings (like with -Wall) but
I am using Delphi 2010. Is it possible to tell Delphi to not generate
If a certain condition is met, is it possible to tell symfony not to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.