0

I have index.html:

<!--#include virtual="/includes/Framework.inc"-->

Inside Framework.inc I have:

<!--#include file="/includes/HTML.inc"-->

However, when I open the page for index.html, after viewing the source code, I see the nested include did not happen and see the full include directive:

<!--#include file="/includes/HTML.inc"-->

How can we make sure nginx supports multiple levels of HTML includes?

1 Answer 1

2

Nginx does support nested SSI includes. However the SSI module processes only the text/html MIME type content by default, and your .inc files are most likely returned with something else in the Content-Type response HTTP header. You can adjust your global MIME types to include .inc extension or specify additional MIME types to process with the ssi_types directive, however I'd rather define an additional location for the /includes/ directory content:

location /includes/ {
    internal;
    ssi on;
    types {
        text/html  html htm inc;
    }
}
5
  • Hello Ivan. I have a follow-up question on this. Can we do a SSI on PHP files? The last node/include tries to include test.php, which contains <?php echo(12345); ?>. But all we see in the source code is the content of test.php. I did try to tweak the types: ssi on; types { text/html html htm inc php; } Jun 3, 2022 at 5:57
  • You are not limited to static content, SSI can be applied to any location, even those that have an HTTP proxy_pass or FCGI fastcgi_pass content handlers. However if you want to include content from those locations, you should do it is using a virtual subrequest, and (obviously) SSI should be turned on for those locations. Jun 3, 2022 at 6:07
  • oh la la, new topics there. lol virtual subrequest eh?..interesting monster whatever that is... Jun 3, 2022 at 6:23
  • This is a static file inclusion (using a filename): <!--#include file="HTML.inc"-->. This is an inclusion of subrequest response (using an URI): <!--#include virtual="/test.php"-->. Subrequests is an internal nginx feature, widely used by a couple of modules (the most known example maybe an auth_request_module); the same internal nginx API is used by SSI virtual includes. /test.php here is an URI that should go through the default PHP handler location (usually something like location ~ \.php$ { ... }) to be interpreted via PHP-FPM. Jun 3, 2022 at 6:31
  • Genius! Wow, that worked. The include against a PHP file inside a virtual directory does not work and pulls the content of the PHP file. I did this, which may be overkill: location /includes/ { alias "Z:/Virtual Folders/Includes/"; ssi on; types { text/html html htm inc php; } location ~ \.php$ { ssi on; types { text/html html htm inc php; } fastcgi_param SCRIPT_FILENAME $request_filename; } } Jun 3, 2022 at 6:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .