3
我想设置nginx缓存静态文件,如图像,CSS和JS。Nginx缓存 - 图像,越来越404
这是我的conf。
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location/{
root /var/www/site;
index index.html index.htm;
}
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
当我试图使用这个,我得到404的所有文件,当我删除位置〜* ...我可以完美地检索所有文件。我有我的档案/var/www/site/images/*/*.jpg
。我在这里错过了什么?
我使用资产的URL重写,为什么我需要在这里指定根路径? – user1658296 2015-11-02 07:27:29
@ user1658296 要么必须在服务器{}中指定全局外部位置的根目录,要么必须为指定的每个位置指定它。 – Philip 2015-11-02 09:44:13