Nginx

Configure And Enabling SSI (Server Side Include ) In Nginx And Apache

server-side-includes
mm
Written by Santosh Prasad

Recently I faced on issue with shtml file. Include was not working in shtml file. Developer was unable to find the reason that’s why he ask me to fix and resolve this issue.  After doing some effort I found that SSI was not enabled on server side.

What is SSI (Server Side Include ) ?

Server Side Include is server side interpreted scripts language.It mostly used in web.
Use of SSI is to include the file into web page.

It looks like this :

#vim index.shtml

<!--/header-part-->

<!--#include file="header.shtml"-->

Enabling SSI In Nginx :

To enable SSI you will need to edit your nginx.conf and file and “ssi on ” in server side location.

#vim /etc/nginx/conf.d/example.conf

server {

client_max_body_size 2M;

listen 80;
server_name www.example.com;

      ...........

location /school/inter/ {
root /var/www/web1/web;
index index.php index.html index.htm index.shtml;
ssi on;

access_log /var/log/nginx/access.log upstream;
error_log /var/log/nginx/error.log crit;

.............

}

Here I have only enable SSI for /school/inter/ location. You can also enable for whole server put it in ” / ” location like below.

location / {
 root /var/www/web1/web;
 index index.html index.php index.shtml;
  ssi on;
}

Save file and exit.

Now you will need to restart/reload nginx.

#service nginx reload/restart

Enabling SSI in apache :

To enable SSI in Apache you can use .httaccess file in Apache root directory. We can also edit httpd.conf file.

You can enable SSI for multiple file extension.

#vim /var/www/web1/web/.htaccess

RewriteEngine On AddHandler server-parsed .html AddHandler server-parsed .shtml AddHandler server-parsed .htm

Save and exit.

Thanks:)

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment