Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在运行于Nginx的wordpress中覆盖某些url的expires头_Php_Wordpress_Nginx_Header - Fatal编程技术网

Php 如何在运行于Nginx的wordpress中覆盖某些url的expires头

Php 如何在运行于Nginx的wordpress中覆盖某些url的expires头,php,wordpress,nginx,header,Php,Wordpress,Nginx,Header,我在Nginx平台上运行wordpress,并分别在.php和静态资产上设置了expires头。但现在需要使用nginx在wordpress中的某些url中添加自定义expires头。我曾尝试添加位置块,但它似乎被用.php块编写的expires头覆盖 我已经创建了一个名为sports的wordpress页面,希望提供没有过期标题的url,其余url的过期标题应为10分钟 我的配置供参考: 服务器{ 听0.0.0.0:80;#服务器的公共IP地址 服务器名称www.abc.com;#您的域名 i

我在Nginx平台上运行wordpress,并分别在.php和静态资产上设置了expires头。但现在需要使用nginx在wordpress中的某些url中添加自定义expires头。我曾尝试添加位置块,但它似乎被用.php块编写的expires头覆盖

我已经创建了一个名为sports的wordpress页面,希望提供没有过期标题的url,其余url的过期标题应为10分钟

我的配置供参考:

服务器{
听0.0.0.0:80;#服务器的公共IP地址
服务器名称www.abc.com;#您的域名
index.php index.html;
root/srv/www;#WordPress安装的绝对路径
将$no_缓存设置为0;
尝试_文件$uri$uri//index.php;
该国政府官员(ogg | ogg | ogv | ogg | ogg | ogg | ogg | ogg | ogg | ogv | ogv | ogv | svg | svg|俄俄T | otf | otf | otf瓦夫夫|沃夫124夫夫124政政政政政政政政政政夫1244 |瓦夫|加加加加加加在场在场在场在场在场在场1244;ttf 124;ttf 124;ttf 124;ttf 1244|基基基基基基基基政政政政政政政夫124;原子原子原子原子rtf | flv | pdf)美元{
访问注销;未注销;过期365d;
}
地点/{
try_files$uri$uri//index.php?$args;
距离+10m;
}
位置~.php${
尝试_文件$uri/index.php;
包括fastcgi_参数;
fastcgi_pass 127.0.0.1:9000;
将$no_缓存设置为0;
添加_头缓存控制公共;
距离+10m;
}
地点~*/体育
{
到期日-1;
}
}

类似于
/sports/
的uri实际上被路由到
/index.php
,其参数包含
$request\u uri
的值。在
nginx
中,所有这些都由
.php
位置块处理,并在该块和该块中单独使用
expires
指令的值

一种可能的解决方案是将
expires
指令的值设为变量:

location ~ \.php$ {
    expires $expires;
    ...
}
并根据原始请求URI(
$request\u URI
)创建值的
映射

请注意,
map
指令位于
http
块中,或与
服务器
块处于同一级别


有关详细信息,请参阅和。

在Wordpress中使用会不会更容易?是的,可以这样做,但在服务器上会更好,因为这样可以避免额外的php调用和开发错误。此逻辑属于应用程序而不是服务器,但这只是我个人的观点。请尝试。但出现此错误:-nginx:[emerg]“expires”指令在/etc/nginx/sites enabled/abc.com.confUpdate中的值无效:现在才知道,如果nginx版本<1.7.9,expires指令只支持变量。我还没试过,但应该可以用。:)
map $request_uri $expires {
    default off;
    ~^/sports +10m;
}
server {
    ...
}