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

  • Home
  • SEARCH
  • 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 8170143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:04:32+00:00 2026-06-06T21:04:32+00:00

I have a nginx + thin + Rails 3.2 setup. Currently I am trying

  • 0

I have a nginx + thin + Rails 3.2 setup. Currently I am trying to setup nginx so it can serve cached pages directly.

However nginx still pass *.html request to Rails in the following nginx configuration files. The html files exists in public folder, and nginx does find them, just that they are still passed to Rails.

upstream site {
  server unix:/home/site/deploy/site/shared/pids/thin.0.sock;
}

server {
  listen 80;
  server_name www.example.com;
  rewrite ^(/.*) http://example.com$1 permanent;
}

# asset server
server {
  listen 80;
  server_name assets.example.com;
  expires max;
  add_header Cache-Control public;
  charset utf-8;
  root   /home/site/deploy/site/current/public/;
}

# frontend
server {
  listen 80;
  server_name .example.com;
  charset utf-8;

  root   /home/site/deploy/site/current/public/;
  index  index.html;

  location ~* ^.+.(jpg|jpeg|gif|png|swf|zip|rar|doc|xls|exe|pdf|ppt|txt|tar)$ {
    root /home/site/deploy/site/current/public/;
    expires max;
    break;
  }

  # serve static files
  if (-f $request_filename) {
    break;
  }

  gzip on;

  location / {
    proxy_set_header  X-Real-IP  $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    if (-f $request_filename) {
      break;
    }

    if (-f $document_root/cache/$host/$uri/index.html) {
      rewrite (.*) /cache/$host/$1/index.html break;
    }

    if (-f $document_root/cache/$host/$uri.html) {
      rewrite (.*) /cache/$host/$1.html break;
    }

    if (-f $document_root/cache/$host/$uri) {
      rewrite (.*) /cache/$host/$1 break;
    }

    proxy_pass http://site;
    break;
  }
}

I am new to nginx, and this configuration file is copied from previous projects I have not worked on, so this is probably a very newbie question.

  • 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-06T21:04:34+00:00Added an answer on June 6, 2026 at 9:04 pm

    To allow nginx to serve static cached pages you need to use try_files, let me share the config:

    upstream site {
      server          unix:/home/site/deploy/site/shared/pids/thin.0.sock fail_timeout=0;
    }
    
    server {
      listen          80;
      server_name     www.example.com;
      rewrite ^(/.*)  http://example.com$1 permanent;
    }
    
    server {
      listen          80;
      server_name     example.com;
      charset         utf-8;
    
      root            /home/site/deploy/site/current;
      try_files       $uri/index.html $uri @thin;
    
      gzip on;
    
      location @thin {
        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header  Host $http_host;
        proxy_redirect    off;
        proxy_pass        http://site;
      }
    
      location ~* ^.+.(jpg|jpeg|gif|png|swf|zip|rar|doc|xls|exe|pdf|ppt|txt|tar)$ {
        root             /home/site/deploy/site/current/public/;
        expires          max;
        break;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have nginx setup, acting as a reverse proxy to apache. However, I need
I have an application running on thin 1.2.11 behind nginx. I was trying to
I have small application on Rails 2.3.2, served with nginx+thin(127). OS FreeBSD 7.1, DB
I have a rails application running on Nginx which needs to serve files for
I have an application running on Rails 3.0.7, thin 1.2.11, and nginx 0.7.65. The
I've just got my first VPS & have set up NGinx, Ruby, Rails &
Now that I have nginx setup I need to be able to hide my
I have the nginx upload module handling site uploads, but still need to transfer
I had a rails 3 app on Nginx/Passenger that I just moved to Nginx/Thin
I have Nginx with Passenger. In nginx.conf I have line: user pass users; and

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.