Question

I want to do server side include and i have nginx server installed in my machine and i cant find a way to enable ssi in nginx.conf file? all i can find from the internet is

syntax: ssi on | off;
default:    
ssi off;
context:    http, server, location, if in location
Was it helpful?

Solution

Enable ssi on the location context. In my case i want it on root

location / {
   ssi on;
}

OTHER TIPS

It looks like you were having the same problem I was having; finding a crystal clear explanation of how to enable SSI on NGINX. Crystal Clear entails not just which syntax to use, but the format, and exactly where to include it. I figured it out and it's not that difficult, but the lack of clear instructions on the internet was frustrating.

You'll need to open up the nginx.conf file and look for the section that is formatted as follows (I've included the 'ssi on' syntax as well):

location / {
            root   E:\website\FinalJRLWeb;
            index  index.html index.shtml;
            ssi on;
        }

It took me a bit to realize the location, but it's really as simple as adding the line 'ssi on' right underneath the specified index file names (and it should be able to really go anywhere you'd like, I don't imagine the order matters, just as long as it's within the two brackets {}).

After that, to verify that SSI is working on your NGINX server, add the following line anywhere in the 'body' tag of a blank html page

<!--#echo var="DATE_LOCAL" -->

and save it with the extension .shtml in your web server's root directory.

You should see the server's local date and time displayed upon visiting your page. I realize this is almost a year old, but after my frustration trying to find clear instructions, I wanted to do my best to try and provide clear instructions for anyone else that may need them. So hopefully this will help someone out!

Here's NGINX's documentation page on SSI (which honestly was not helping me as much as I would have liked, but it nonetheless is useful, and can only become more and more useful)

http://nginx.org/en/docs/http/ngx_http_ssi_module.html#ssi_last_modified

By default ssi is only apply to the text/html MIME Type; which might offer you frustration, though clearly documented here http://nginx.org/en/docs/http/ngx_http_ssi_module.html#ssi_types

you may need to add

ssi on;
ssi_types *;  # Or something more specific

Enabling SSI on NGINX for a single domain

To enable SSI for just one domain (limiting possible security holes), you can add it as follows to the .conf file for that domain - in Debian these are (controversially for some) stored in the Apache-like system under "etc/nginx/sites-available".

server {
  server_name mydomain.com;

  root /home/username/html;
  index index.html index.shtml;

  location / {
    ssi on;
    ...otherstuffhere
  }
}

The crucial parts:

  • index index.html index.shtml;
  • ssi on;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top