【发布时间】:2016-01-10 01:22:29
【问题描述】:
我在 Nginx 平台上运行 wordpress,并在 .php 和静态资产上分别设置了 expires 标头。但现在的要求是使用 nginx 将自定义过期标头添加到 wordpress 中的某些 url。我曾尝试添加位置块,但似乎它被 .php 块中写入的 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 action 不是更容易吗?
-
是的,它可以完成,但在服务器上会更好,因为它可以避免额外的 php 调用和开发错误
-
IMO 这个逻辑属于应用程序而不是服务器,但这只是我个人的看法。
标签: php wordpress nginx header