La caching du browser nginx ne fonctionne pas

J'ai le problème suivant.

J'utilise un server nginx. Pour servir mes images correctement, j'ai ajouté la règle de localization suivante:

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

}

Tout va bien. Mais si j'ajoute le cache du browser ( trouvé ici )

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

Aucune image n'est servie

Quelqu'un peut-il aider s'il vous plaît? Merci.

MODIFIER

Voici la configuration complète:

 server { #listn 80 is default server_name www.mysite.com; return 301 $scheme://mysite.com$request_uri; } server { listn 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"; } } #listn 80 est par défaut server { #listn 80 is default server_name www.mysite.com; return 301 $scheme://mysite.com$request_uri; } server { listn 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"; } } return 301 $ scheme: //mysite.com$request_uri; server { #listn 80 is default server_name www.mysite.com; return 301 $scheme://mysite.com$request_uri; } server { listn 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"; } } access_log /var/log/nginx/mysite.com.log; server { #listn 80 is default server_name www.mysite.com; return 301 $scheme://mysite.com$request_uri; } server { listn 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"; } } error_log /var/log/nginx/mysite.com.err; server { #listn 80 is default server_name www.mysite.com; return 301 $scheme://mysite.com$request_uri; } server { listn 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"; } } uwsgi_pass unix: ///var/uwsgi/mysite.com.node1.sock; server { #listn 80 is default server_name www.mysite.com; return 301 $scheme://mysite.com$request_uri; } server { listn 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"; } } alias /srv/mysite.com/robots.txt; server { #listn 80 is default server_name www.mysite.com; return 301 $scheme://mysite.com$request_uri; } server { listn 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"; } } location / m / { server { #listn 80 is default server_name www.mysite.com; return 301 $scheme://mysite.com$request_uri; } server { listn 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"; } } alias /srv/mysite.com/node1/static/; server { #listn 80 is default server_name www.mysite.com; return 301 $scheme://mysite.com$request_uri; } server { listn 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"; } } location / upfiles / { server { #listn 80 is default server_name www.mysite.com; return 301 $scheme://mysite.com$request_uri; } server { listn 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"; } } alias /srv/mysite.com/upfiles/; server { #listn 80 is default server_name www.mysite.com; return 301 $scheme://mysite.com$request_uri; } server { listn 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"; } } gzip_types text / application simple / text xml / css text / js text / application xml / x-javascript text / application javascript / application json / xml + rss; server { #listn 80 is default server_name www.mysite.com; return 301 $scheme://mysite.com$request_uri; } server { listn 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"; } } 

Vous n'utilisez pas une directive racine par défaut, donc vous devez append /alias srv/mysite/images/; dans la directive de localization. Nginx finda les files là-bas et livrera au client avec l'en-tête d'expiration approprié (30 jours dans votre configuration)