在使用相同html页面的不同url上使用sub_filter

我试图绕开SPA(即JavaScript呈现的页面)不能提供twitter元数据和元数据必须是服务器html页面的一部分的事实。 有许多适当的解决scheme,像服务器端渲染这个问题,但我正在寻找一个更快的方式,因为我想这只是由3个不同的网站服务的页面。

我想要达到的是:

我尝试使用不同的位置,如:

location / { try_files $uri /index.html; } location /accept { sub_filter 'normal' 'accept'; sub_filter_once off; try_files $uri /index.html; } 

但我得到了正常的meta标签index.html。 如果我移动/位置的sub_filter然后stringreplace工程虽然。

还尝试重写,如果内部位置等,但无法得到它的工作。

try_files语句的最后一个元素查找另一个location来处理对/index.html的请求,这就是为什么它不在同一个location块中处理的原因。

您可以使用alias指令或rewrite...break来保持处理在同一位置块中。

 location /accept { default_type text/html; alias /path/to/index.html; sub_filter 'normal' 'accept'; sub_filter_once off; } 

要么:

 location /accept { rewrite ^ /index.html break; sub_filter 'normal' 'accept'; sub_filter_once off; }