版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cn_yaojin/article/details/81775208
1、 nginx 配置:
server {
listen 80;
server_name 127.0.0.1;
location /demo {
alias D:/openresty-win64/html/;
access_by_lua_file lua/index.template.lua;
#index index.html index.htm;
}
}
2、lua脚本:
local template = require "resty.template"
-- request uri
local url = ngx.var.uri
template.render("index.html",{ message =url})
3、index.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome to OpenResty!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to OpenResty!</h1>
<p>Hi,{{message}}</p>
<p>For online documentation and support please refer to
<a href="https://openresty.org/">openresty.org</a>.<br/>
Commercial support is available at
<a href="https://openresty.com/">openresty.com</a>.</p>
<p><em>Thank you for flying OpenResty.</em></p>
</body>
</html>
4、template.lua 下载地址:https://github.com/bungle/lua-resty-template