0

I've been having a bit of difficulty setting up nginx on my ubuntu server. Right now its configured to proxy another website. I want to add some content to the main page right after <body>. I used:

subs_filter '<body>' '<body>' My content;

This works great, the only problem is that it's at every page, How can I use an if statement or something to make it only appear on the homepage. I tried going with

if ($uri ~ 'index.php') then do the above filter but that gives an error saying nginx: [emerg] "subs_filter" directive is not allowed here.

I looked it up but had a lot of trouble finding what I need :(.

4

1 回答 1

2

根据nginx文档 subs_filter,可能会在http,serverlocation上下文中使用。

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

location = /index.php {
    subs_filter '<body>' '<body>' My content;
    # other things you would do for index.php
}
于 2013-05-01T06:28:22.787 回答