初學 Nginx (一) SSI 的作用


SSI:Server Side Include,是一種基於服務端的網頁制作技術,

Nginx ssi 的例子如下:

It took a little while to figure this out and it’s handy for creating one-off sites with “dynamic” content without a web framework.

user nginx; worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; tcp_nopush on; keepalive_timeout 10; gzip on; server { server_name localhost; charset utf-8; access_log /var/log/nginx/access.log; root /var/www; location = / { rewrite ^ /home redirect; } location / { ssi on; set $inc $request_uri; if (!-f $request_filename) { rewrite ^ /index.html last; } if (!-f $document_root$inc.html) { return 404; } } } } 

Then if you have an index.html file similar to this:

<html> <body> <!--# include file="$inc.html" --> </body> </html> 

it will now include (via SSI) whatever page is requested. So for example /home would include home.html into index.html. This makes it easy to have a common style (headers and footers) without resorting to PHP or a framework.

It assumes home.html exists.

從列子不難看出 ssi的 的作用, 有點像jsp的include 標簽 ,不同的是  ssi 引用的 頁面 來自靜態頁面 ,是不經過后台的。

這里是一點點 體會。有不同看法的歡迎大家經常討論。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM