local function local_print(str)
local dbg = io.open("conf/lua/logs/output.txt", "a+")
local str = str or ""
if dbg then
dbg:write(str..'\n')
dbg:close()
end
end local template = require("resty.template")
local redis = require("resty.redis")
local mysql = require("resty.mysql") local context = {
title = "测试",
name = "张三",
description = "<script>alert(1);</script>",
script = "alert(1)",
age = 20,
hobby = {"电影", "音乐", "阅读"},
-- score = {"语文" = 90, "数学" = 80, "英语" = 70},
score2 = {
{name = "语文", score = 901},
{name = "数学", score = 810},
{name = "英语", score = 710},
},
file = 'xiaowu'
} -- 关闭redis链接
local function close_redes( red )
if not red then
return
end
local ok, err = red:close()
if not ok then
local_print("close redis error:" .. err)
end
end -- 创建实例
local red = redis:new()
-- 设置超时(毫秒)
red:set_timeout(2000)
-- 建立连接
local ip = "192.168.10.10"
local port = 7000
local ok, err = red:connect(ip, port)
if not ok then
return
end
-- 没有密码不需要写
-- local res, err = red:auth("")
-- if not res then
-- local_print("connect to redis error : " .. err)
-- return
-- end -- 调用api进行操作
res, err = red:set("msg", "hello world")
if not res then
local_print("set msg error : " .. err)
end local resp, err = red:get("msg")
if not resp then
local_print("get msg erro:" .. err)
else
context.title = resp
end close_redes(red) ---------------------------------------------------------------------------------------
local function close_db( db )
if not db then
return
end
db:close()
end -- 创建实例
local db, err = mysql:new()
if not db then
local_print("new mysql error:" .. err)
return
end
-- 设置超时时间(毫秒)
db:set_timeout(5000) local props = {
host = "192.168.10.5",
port = 3306,
database = "union",
user = "rshy",
password = "123456"
} local res, err, errno, sqlstate = db:connect(props) if not res then
local_print("connect to mysql error : " .. err, " , errno : " .. errno, " , sqlstate : " .. sqlstate)
return close_db(db)
else
local select_sql = "select teacherid from teacher limit 2"
res, err, errno, sqlstate = db:query(select_sql)
if not res then
local_print("select error : " .. err, " , errno : " .. errno, " , sqlstate : " .. sqlstate)
return close_db(db)
else
for k, v in pairs(res) do
local_print(k .. v.teacherid)
end
end end
--------------------------------------------------------------------------------------- template.render("t1.html", context)

  

#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 80;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; # luatext
location /luatest {
access_log logs/luatest.access.log main;
default_type text/html;
# 即缓存lua代码,即每次lua代码变更必须reload nginx才生效,
# 如果在开发阶段可以通过lua_code_cache off;关闭缓存,
# 这样调试时每次修改lua代码不需要reload nginx;但是正式环境一定记得开启缓存
lua_code_cache on;
# content_by_lua_block {
# ngx.say("<p>hello, world ...... </p>")
# }
# content_by_lua_file conf/lua/test1.lua; header_filter_by_lua_block {
ngx.header.content_length = nil
} body_filter_by_lua_file conf/lua/test1.lua; } location /luatemplatetest {
#first match ngx location(首先匹配位置) html下的templates
set $template_location "/templates";
#then match root read file(其次匹配位置)
set $template_root "C:/openresty/openresty-1.15.8.3-win64/templates"; access_log logs/luatemplatetest.access.log main;
default_type text/html;
# 即缓存lua代码,即每次lua代码变更必须reload nginx才生效,
# 如果在开发阶段可以通过lua_code_cache off;关闭缓存,
# 这样调试时每次修改lua代码不需要reload nginx;但是正式环境一定记得开启缓存
lua_code_cache on;
# content_by_lua_block {
# ngx.say("<p>hello, world ...... </p>")
# }
content_by_lua_file conf/lua/test2.lua;
# 与html同级的目录
# root templates; } # 分发Django服务
location /admin {
access_log logs/admin.access.log main;
proxy_pass http://127.0.0.1:8000;
} # 创建一个新的目录
location /xiaowu {
access_log logs/xiaowu.access.log main;
root html;
index index.html index.htm;
} location /mytest {
access_log logs/mytest.access.log main;
root html;
index index.html index.htm;
} location / {
root html;
access_log logs/host.access.log main;
index index.html index.htm;
} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 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$ {
# proxy_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
#
#location ~ /\.ht {
# deny all;
#}
} server {
listen 443 ssl;
server_name bdsapp.peixun86.com;
# ssl on;
ssl_certificate ssl/3739731_bdsapp.peixun86.com.pem;
ssl_certificate_key ssl/3739731_bdsapp.peixun86.com.key; location / {
access_log logs/access_liu.log main;
root html;
index index.html index.htm;
} location /union {
access_log logs/access_union.log main;
proxy_pass http://test.nadiyi.cn;
} location /merchant {
access_log logs/access_merchant.log main;
proxy_pass http://test.nadiyi.cn;
} } # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename 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;
# }
#} }

  

最新文章

  1. JSON中eval与parse的区别
  2. iOS10 相机相册等权限的使用、检测并引导用户开启权限
  3. 游戏服务器ID生成器组件
  4. 设置 Eclipse 智能代码提示,大幅度减少 alt+/ 使用频率,打每个字都出现代码提示的办法
  5. Python实现类似switch...case功能
  6. Java中关于OOM的场景及解决方法
  7. WebStorm、IntelliJ IDEA、JetBrains、PhpStorm、RubyMine、PyCharm
  8. Entity Framework技巧系列之十 - Tip 37 - 41
  9. 【EntityFramework 6.1.3】个人理解与问题记录
  10. Centos硬盘IO性能检测命令iostat[转]
  11. 从零开始,搭建 AI 音箱 Alexa 语音服务
  12. win 系统设置weblogic 进行定时自动重启并删除其日志和缓存文件,定时监控cpu是否达到100%并重启weblogic服务
  13. Codeforces.24D.Broken robot(期望DP 高斯消元)
  14. Maven项目错误解决小结
  15. TiKV 源码解析系列——如何使用 Raft
  16. springmvc 开涛 拦截器
  17. scrapy爬虫框架之Xpath选择器
  18. week4c:个人博客作业
  19. jfinal控制器添加多个拦截器
  20. MySQL高级第二章——索引优化分析

热门文章

  1. 代码安全丨第六期:XPath注入漏洞样例
  2. SpringCloud(四)GateWay网关
  3. hdu4768 非常规的二分
  4. UVA11549计算器谜题
  5. SQL注入平台第一关,注入?id=1&#39;不报错的问题
  6. 基于MXNET框架的线性回归从零实现(房价预测为例)
  7. Spring Security 入门篇
  8. JUC 并发类概览
  9. 简单说几个MySQL高频面试题
  10. Consul 服务的注册和发现