Hello,<br><br>Thanks for your reply! And I think the limit on the number is proper for most of the conditions. <br><br>However in our case, the index page may have hundreds of SSI 'include' (combined from lots of our sub sites), and the number limitation may not be so proper.<br>
<br>So here I made a patch: For every 'include', a 'parents uri check' is made. The patch is like this:<br><br><span style="color: rgb(102, 102, 102);">diff -crB <a href="http://nginx-0.7.65.org/src/http/modules/ngx_http_ssi_filter_module.c">nginx-0.7.65.org/src/http/modules/ngx_http_ssi_filter_module.c</a> nginx-0.7.65.patch/src/http/modules/ngx_http_ssi_filter_module.c</span><br style="color: rgb(102, 102, 102);">
<span style="color: rgb(102, 102, 102);">*** <a href="http://nginx-0.7.65.org/src/http/modules/ngx_http_ssi_filter_module.c">nginx-0.7.65.org/src/http/modules/ngx_http_ssi_filter_module.c</a> 2011-05-24 18:46:53.676370002 +0800</span><br style="color: rgb(102, 102, 102);">
<span style="color: rgb(102, 102, 102);">--- nginx-0.7.65.patch/src/http/modules/ngx_http_ssi_filter_module.c 2011-05-25 11:19:20.372370002 +0800</span><br style="color: rgb(102, 102, 102);"><span style="color: rgb(102, 102, 102);">***************</span><br style="color: rgb(102, 102, 102);">
<span style="color: rgb(102, 102, 102);">*** 2024,2029 ****</span><br style="color: rgb(102, 102, 102);"><span style="color: rgb(102, 102, 102);">--- 2024,2044 ----</span><br style="color: rgb(102, 102, 102);"><span style="color: rgb(102, 102, 102);"> flags |= NGX_HTTP_SUBREQUEST_IN_MEMORY|NGX_HTTP_SUBREQUEST_WAITED;</span><br style="color: rgb(102, 102, 102);">
<span style="color: rgb(102, 102, 102);"> }</span><br style="color: rgb(102, 102, 102);"><span style="color: rgb(102, 102, 102);"> </span><br style="color: rgb(102, 102, 102);"><span style="color: rgb(102, 102, 102);">+ ngx_http_request_t *ir = r;</span><br style="color: rgb(102, 102, 102);">
<span style="color: rgb(102, 102, 102);">+ for(;ir != NULL;ir = ir->parent) {</span><br style="color: rgb(102, 102, 102);"><span style="color: rgb(102, 102, 102);">+ ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,</span><br style="color: rgb(102, 102, 102);">
<span style="color: rgb(102, 102, 102);">+ " include path: %V, args: %V; parent path: %V, args: %V",</span><br style="color: rgb(102, 102, 102);"><span style="color: rgb(102, 102, 102);">+ uri, &args, &ir->uri, &ir->args);</span><br style="color: rgb(102, 102, 102);">
<span style="color: rgb(102, 102, 102);">+ if (uri->len == ir->uri.len</span><br style="color: rgb(102, 102, 102);"><span style="color: rgb(102, 102, 102);">+ && args.len == ir->args.len</span><br style="color: rgb(102, 102, 102);">
<span style="color: rgb(102, 102, 102);">+ && ngx_strncmp(uri->data, ir->uri.data, uri->len) == 0</span><br style="color: rgb(102, 102, 102);"><span style="color: rgb(102, 102, 102);">+ && ngx_strncmp(args.data, ir->args.data, args.len) == 0) {</span><br style="color: rgb(102, 102, 102);">
<span style="color: rgb(102, 102, 102);">+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,</span><br style="color: rgb(102, 102, 102);"><span style="color: rgb(102, 102, 102);">+ "A loop include \"%V\" is found", uri);</span><br style="color: rgb(102, 102, 102);">
<span style="color: rgb(102, 102, 102);">+ return NGX_HTTP_SSI_ERROR;</span><br style="color: rgb(102, 102, 102);"><span style="color: rgb(102, 102, 102);">+ }</span><br style="color: rgb(102, 102, 102);">
<span style="color: rgb(102, 102, 102);">+ }</span><br style="color: rgb(102, 102, 102);"><span style="color: rgb(102, 102, 102);">+ </span><br style="color: rgb(102, 102, 102);"><span style="color: rgb(102, 102, 102);"> if (ngx_http_subrequest(r, uri, &args, &sr, psr, flags) != NGX_OK) {</span><br style="color: rgb(102, 102, 102);">
<span style="color: rgb(102, 102, 102);"> return NGX_HTTP_SSI_ERROR;</span><br style="color: rgb(102, 102, 102);"><span style="color: rgb(102, 102, 102);"> }</span><br style="color: rgb(102, 102, 102);"><br>
Hope for any reply of my patch !<br><br>And thanks to my fellow 姚伟斌 for reminding me on the 'args' check!<br><br><br><div class="gmail_quote">On Tue, May 24, 2011 at 8:59 PM, Maxim Dounin <span dir="ltr"><<a href="mailto:mdounin@mdounin.ru">mdounin@mdounin.ru</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Hello!<br>
<div><div></div><div class="h5"><br>
On Tue, May 24, 2011 at 10:49:45AM +0800, eagle sbc wrote:<br>
<br>
> Hello,<br>
><br>
> I've encountered a problem about "SSI include infinite loop".<br>
><br>
> We have a system that our editors can compose a html page from some<br>
> templates using SSI. Sometimes unwarily combination will cause infinite<br>
> loop, such as 'A include A', 'A include B, B include A', or even 'A include<br>
> B, B include C, C include A'. And this page will cause nginx eating up all<br>
> memories, and certainly won't serve any more unless we restart nginx.<br>
><br>
> I'm wondering is there any solution for this problem? Or other ways to avoid<br>
> this?<br>
><br>
> I've googled apache and lighttpd, and there also no official solution for<br>
> this, unless lightptd has a patch which will limit the whole 'include'<br>
> count, and I think it's just a tricky way to fix the infinite loop.<br>
><br>
> Thanks a lot for any help!<br>
<br>
</div></div>Number of in-flight ssi includes used to be limited in nginx,<br>
though this limit was broken somewhere near 0.7.25.<br>
<br>
This patch brings it back:<br>
<br>
<a href="http://nginx.org/pipermail/nginx-devel/2011-February/000746.html" target="_blank">http://nginx.org/pipermail/nginx-devel/2011-February/000746.html</a><br>
<br>
Maxim Dounin<br>
<br>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org">nginx@nginx.org</a><br>
<a href="http://nginx.org/mailman/listinfo/nginx" target="_blank">http://nginx.org/mailman/listinfo/nginx</a><br>
</blockquote></div><br><br clear="all"><br>-- <br><font color="#333333"><font face="'comic sans ms', sans-serif">自由是我生命之基石,尊重是我行为之准绳</font></font><div><font color="#333333"><font face="'comic sans ms', sans-serif">也许我以千百种方式生活在这世上,但我坚守我人生之信仰</font></font></div>
<div><font color="#333333"><font face="'comic sans ms', sans-serif">所以,我的朋友</font></font></div><div><font color="#333333"><font face="'comic sans ms', sans-serif">请平视的看着我,</font></font><span style="color: rgb(51, 51, 51);"><font face="'comic sans ms', sans-serif">带着你的微笑</font></span></div>
<div><font color="#333333"><br></font></div><br>