Nginx's SSI

Source: Internet
Author: User

What SSI is: Server Side Include, is a service-side-based Web authoring technology.

The ngx_http_ssi_module module is a filter, Processes SSI (Server Side includes) commands in responses passing through it.

It works by using an SSI directive to include text, pictures, or code information in a Web page before the page content is sent to the client. For repeating content in multiple files, using SSI is an easy way to save content in an include file without having to enter it into all files. The include file is called with a very simple statement that instructs the WEB server to insert the content into the appropriate Web page. Also, when you use the Include file, all changes to the content can be done in one place only.

Above are official or plagiarism claims, the official has a word currently, the list of supported SSI commands is incomplete.

Simply put, the content is processed in an additional way through the Conf configuration before the content is returned to the client. This technique is available for both Apache and IIS.

One of our simplest demos is to add a header.html and footer.html reference to the system's default home page index.html.

The prerequisite is that you have installed nginx-1.9.9 to c:\nginx-1.9.9. If you don't know how to install it, see the previous article.

1. Open c:\nginx-1.9.9\conf\nginx.conf, enable SSI,

I was enabled under the server, of course you can also under Location, add code, first drive enabled, the second line is the error processing, there are additional modifications, the port is modified to 2016.

To add code to the server:

SSI on;

Ssi_slient_errors on;

  

#user nobody;worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid;events {worker_connections 1024;}    HTTP {include mime.types;    Default_type Application/octet-stream;  #log_format Main ' $remote _addr-$remote _user [$time _local] "$request" ' # ' $status $body _bytes_sent    "$http _referer" ' # ' "$http _user_agent" "$http _x_forwarded_for";    #access_log Logs/access.log Main;    Sendfile on;    #tcp_nopush on;    #keepalive_timeout 0;    Keepalive_timeout 65;    #gzip on;        server {Listen 2016;        server_name Localhost;ssi on;ssi_silent_errors on;        #charset Koi8-r;        #access_log Logs/host.access.log Main;            Location/{root HTML;        Index index.html index.htm;        } #error_page 404/404.html; # REDIRECT Server error pages to the static Page/50x.html # Error_page 502 503 504/50x.html;        Location =/50x.html {root html; } # Proxy The PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ {# ProX        Y_pass http://127.0.0.1;        #} # Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ {        # root HTML;        # Fastcgi_pass 127.0.0.1:9000;        # Fastcgi_index index.php;        # Fastcgi_param Script_filename/scripts$fastcgi_script_name;        # include Fastcgi_params; #} # Deny access to. htaccess files, if Apache ' s document Root # concurs with Nginx ' s one # #l        ocation ~/\.ht {# deny all;       #}} # Another virtual host using mix of ip-, name-, and port-based configuration # #server {# listen    8000;    # Listen somename:8080;  # server_nameSomename alias Another.alias;    # location/{# root HTML;    # index index.html index.htm;    #} #} # HTTPS Server # #server {# listen 443 SSL;    # server_name localhost;    # ssl_certificate Cert.pem;    # Ssl_certificate_key Cert.key;    # Ssl_session_cache shared:ssl:1m;    # ssl_session_timeout 5m; # ssl_ciphers high:!anull:!    MD5;    # ssl_prefer_server_ciphers on;    # location/{# root HTML;    # index index.html index.htm; #    }    #}}

  

2. Open the c:\nginx-1.9.9\html\index.html and modify it as follows:

The modification is the content before and after adding

<!--#include virtual= "header.html"-

<!--#include virtual= "footer.html"-

<!DOCTYPE HTML><HTML><Head>    <title>Welcome to nginx!</title>    <style>Body{width:35em;margin:0 Auto;font-family:Tahoma, Verdana, Arial, Sans-serif;        }    </style></Head><Body>    <!--#include virtual= "header.html" -    <H1>Welcome to nginx!</H1>    <P>If you see this page, the Nginx Web server is successfully installed and working.    Further configuration is required. </P>    <P>For online documentation and refer<ahref= "http://nginx.org/">nginx.org</a>.<BR/>commercial support was available at<ahref= "http://nginx.com/">Nginx.com</a>. </P>    <P><em>Thank for using Nginx.</em></P>    <!--#include virtual= "footer.html" -</Body></HTML>

3. Create the header.html below c:\nginx-1.9.9\html, as follows:

<div>
Content in head!
</div>

4. Create the footer.html below c:\nginx\1.9.9\html, as follows:

<div>
Content in footer!
</div>

5. Open cmd,

CD c:\nginx-1.9.9

Start Nginx

6. Open the browser and enter http://localhost:2016

The content becomes:

Content in head! Welcome to nginx!

If you see this page, the Nginx Web server is successfully installed and working. Further configuration is required.

For online documentation and the refer to nginx.org.
Commercial support was available at nginx.com.

Thank for using Nginx.

Content in footer!

Reference article:

Http://nginx.org/en/docs/http/ngx_http_ssi_module.html#ssi

How to Setup HTML Server Side includes SSI on Apache and Nginx
http://www.thegeekstuff.com/2014/07/server-side-includes/

Dynamic SSI Example

https://www.nginx.com/resources/wiki/start/topics/examples/dynamic_ssi/

Nginx's SSI

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.