Accept cookies for analytics, social media, and advertising, or learn more and adjust your preferences. These cookies are on by default for visitors outside the UK and EEA. Privacy Notice.
これを理解するには少し時間が掛かり、webフレームワーク無しで “動的な” コンテントを持つ一回限りのサイトを作成するのに便利です。
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;
}
}
}
}
そして、これに似たようなindex.htmlファイルを持つ場合:
<html>
<body>
<!--# include file="$inc.html" -->
</body>
</html>
これで、どのようなページがリクエストされても(SSIを通じて)includeされるでしょう。つまり、例えば /home は home.htmlを index.html にincludeするでしょう。これにより、PHPあるいはフレームワークの助けを借りることなく共通のスタイル(ヘッダおよびフッタ)を持つことが簡単になります。
home.html が存在すると仮定します。