Ruby on Rails Thursday, May 29, 2014



On Thursday, May 29, 2014 4:22:27 AM UTC-4, himanshu saxena wrote:

I am facing an issue with rails application deployed on Amazon with nginx 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 folder named html_app. And all the css, js and images are kept inside that html_app folder with the same name. see below:
public/html_app/js/test.js
public/html_app/css/test.css
public/html_app/img/test.png
public/html_app/index.html

In order to use browser caching, I have given below configuration for nginx 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 ?

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 vs regex expressions.  The following might work

location ~* \.(jpg|jpeg|gif|css|png|js|ico)$ {

 

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/6be38f5e-d17e-4f85-a911-b49a2f89ca61%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment