我正在尝试设置Nginx来缓存静态文件,例如图像,css和js.
这是我的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中.我在这里错过了什么?
最佳答案
问题在于
原文链接:https://www.f2er.com/nginx/434584.htmllocation ~* \.(?:ico|css|js|gif|jpe?g|png)${
expires max;
add_header Pragma public;
add_header Cache-Control "public,proxy-revalidate";
}
它应该设置根路径.
location ~* \.(?:ico|css|js|gif|jpe?g|png)${
root /var/directory/...
expires max;
add_header Pragma public;
add_header Cache-Control "public,proxy-revalidate";
}