Forum: Ruby on Rails Browser Caching with Rails 4.0.2 with Nginx and unicorn

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
himanshu saxena (Guest)
on 2014-05-29 10:23
(Received via mailing list)
I am facing an issue with rails application deployed on Amazon with
and unicorn. I am not using any controller or action to render a view,
rather I am using a simple html page inside a sub folder of public
named html_app. And all the css, js and images are kept inside that
html_app folder with the same name. see below:

In order to use browser caching, I have given below configuration for
in config/nginx.conf, see below:

upstream unicorn {
server unix:/tmp/unicorn.cache_app.sock fail_timeout=0;

server {
listen 80;
server_name x.x.x.x;
root /home/ec2-user/cache_app/public;

# location ^~ /home/ec2-user/cache_app/public {
# gzip_static on;
# expires max;
# add_header Cache-Control public;
# }

location ^~ /.(jpg|jpeg|gif|css|png|js|ico)/ {
# gzip_static on;
expires 1d;
# add_header Cache-Control public;
# add_header Last-Modified "";
# add_header ETag on;
# break;

try_files $uri/index.html $uri @unicorn <>;
location @unicorn <> {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;

error_page 500 502 503 504 /500.html;
client_max_body_size 20M;
keepalive_timeout 10;


Everything is working except, expires in location block, if I define
expires globally, it works, but not inside the location.

Please suggest, where am I wrong ?

mike2r (Guest)
on 2014-05-30 02:53
(Received via mailing list)
On Thursday, May 29, 2014 4:22:27 AM UTC-4, himanshu saxena wrote:
> root /home/ec2-user/cache_app/public;
> # add_header Cache-Control public;
> proxy_pass http://unicorn;
> Please suggest, where am I wrong ?
> Thanks

I'm a little rusty on this, but i think it's your regex.  you definitely
need a $ sign.  as it's written, it will match only the filenames .jpg,
.peg, etc (filenames that actually have only those four characters).  I
also seem to remember the ^~ is used when specifying directory entries
regex expressions.  The following might work

location ~* \.(jpg|jpeg|gif|css|png|js|ico)$ {
This topic is locked and can not be replied to.