对于我的 NGINX 服务器,我设置了一个虚拟服务器来分发静态内容。目前我正在尝试设置它以便图像具有到期日期。但是,当我为此创建一个位置指令时,一切都会导致 404。
我现在的配置是这样的:
/srv/www/static.conf
server {
listen 80;
server_name static.*.*;
location / {
root /srv/www/static;
deny all;
}
location /images {
expires 1y;
log_not_found off;
root /srv/www/static/images;
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,此文件包含在 /etc/nginx/nginx.conf 中的 http 指令中
我试图访问图像,在,让我们说...... static.example.com/images/screenshots/something.png。果然,图像也存在于/srv/www/static/images/screenshots/something.png。但是,转到上述地址不起作用,只是告诉我404 Not Found。
但是,如果我删除location /images并更改location /为以下内容...
location / {
root /srv/www/static;
}
Run Code Online (Sandbox Code Playgroud)
有用!我在这里做错了什么?