Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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/7/google-maps/4.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
String nginx-替换主页上的页面内容_String_Nginx_Replace - Fatal编程技术网

String nginx-替换主页上的页面内容

String nginx-替换主页上的页面内容,string,nginx,replace,String,Nginx,Replace,在我的ubuntu服务器上设置nginx有点困难。现在它被配置为代理另一个网站。我想在之后的主页上添加一些内容。我用过: subs\u过滤器“”“”我的内容 这很好用,唯一的问题是它在每一页上,我如何使用if语句或其他东西使它只出现在主页上。我试着和你一起去 如果($uri~'index.php')则执行上述筛选,但会出现一个错误,说明此处不允许使用nginx:[emerg]“subs\u filter”指令 我查了一下,但很难找到我需要的:(.根据subs\u filter可以在http,服务

在我的ubuntu服务器上设置nginx有点困难。现在它被配置为代理另一个网站。我想在
之后的主页上添加一些内容。我用过:

subs\u过滤器“”“”我的内容

这很好用,唯一的问题是它在每一页上,我如何使用if语句或其他东西使它只出现在主页上。我试着和你一起去

如果($uri~'index.php')
则执行上述筛选,但会出现一个错误,说明此处不允许使用
nginx:[emerg]“subs\u filter”指令

我查了一下,但很难找到我需要的:(.

根据
subs\u filter
可以在
http
服务器和
位置
上下文中使用

因此,为了仅为index.php页面激活过滤器

location=/index.php{
subs_筛选器“”“”我的内容;
#您将为index.php执行的其他操作
}

Im在位置上下文中使用它,问题是我的根/主页不是index.php,它是代理的,所以我甚至不知道它是什么,它只是/。但是如果你使用/作为适用于每个页面的位置。如果你使用
location=/{
,它将只匹配
http://domain.com/
页面(注意
=
)啊!!我知道我错过了什么,非常感谢。
location = /index.php {
    subs_filter '<body>' '<body>' My content;
    # other things you would do for index.php
}