我在Nginx平台上运行wordpress,并分别在.php和静态资源上设置了过期标题。但现在需要使用nginx将自定义过期头添加到wordpress中的某些URL。我已经尝试添加位置块,但似乎它被覆盖在.php块中的expires标题覆盖。如何覆盖在Nginx上运行的wordpress中的某些URL的expires标题
我创建了一个名为sports的wordpress页面,并且希望提供没有过期标题的url,并且对于其他url的过期标头应为10分钟
我的配置以供参考:
server {
listen 0.0.0.0:80; # your server's public IP address
server_name www.abc.com; # your domain name
index index.php index.html ;
root /srv/www; # absolute path to your WordPress installation
set $no_cache 0;
try_files $uri $uri/ /index.php;
location ~*^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|css|woff|js|rtf|flv|pdf)$ {
access_log off; log_not_found off; expires 365d;
}
location/{
try_files $uri $uri/ /index.php?$args;
expires modified +10m;
}
location ~ .php$ {
try_files $uri /index.php;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
set $no_cache 0;
add_header Cache-Control public;
expires modified +10m;
}
location ~* /sports
{
expires -1;
}
}
在Wordpress中使用[send_headers动作](http://codex.wordpress.org/Plugin_API/Action_Reference/send_headers)不会更容易吗? –
是的,它可以做到,但会更好的服务器,因为它会逃脱额外的PHP电话和发展的错误 – user3136348
IMO此逻辑属于应用程序而不是服务器,但这只是我个人的意见。 –