2

I have the following problem.

I'm using a nginx server. To serve my images correctly I've added following location rule:

location /images/ {
   alias /srv/mysite/images/;
   autoindex off;

}

Everything is ok. But if I add the the Browser Caching (found here)

location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
expires 30d;
add_header Pragma public;
add_header Cache-Control "public";
} 

No images are served

Can someone help please? Thanks.

EDIT

Here is the full configuration:

server {
#listen 80 is default
server_name www.mysite.com;
return 301 $scheme://mysite.com$request_uri;
  }
server {
listen   80;

server_name mysite.com;
access_log /var/log/nginx/mysite.com.log;
error_log /var/log/nginx/mysite.com.err;

location / {
    include uwsgi_params;
    uwsgi_pass unix:///var/uwsgi/mysite.com.node1.sock;
}

location = /robots.txt {
    alias /srv/mysite.com/robots.txt;
}

location /m/ {
    alias /srv/mysite.com/node1/static/;
    autoindex off;
    expires max;
}

location /upfiles/ {
    alias /srv/mysite.com/upfiles/;
    autoindex off;
}

##
# Gzip Settings
##

gzip on;
gzip_disable "msie6";

gzip_comp_level 6;
#gzip_comp_level 9;
gzip_min_length  1100;
gzip_buffers 16 8k;
gzip_proxied any;
# gzip_http_version 1.1;
gzip_types       text/plain application/xml text/css text/js text/xml application/x-javascript text/javascript application/json application/xml+rss;



####
##Browser Cache
####

location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
expires 30d;
add_header Pragma public;
add_header Cache-Control "public";
} 


}
alisia123
  • 139
  • 4
  • 1
    Show the full (redacted) configuration. It's usually because the location block is in the wrong place. – Nathan C Apr 28 '15 at 16:50

1 Answers1

1

You're not using a default root directive so you should add /alias srv/mysite/images/; inside the location directive. Nginx will find the files there and deliver to the client with the proper expiration header (30 days in your configuration)

hdanniel
  • 4,293
  • 23
  • 25