openresty - nginx - 配置
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;
# }
#} }
openresty - nginx - 配置的更多相关文章
- openresty(nginx) 配置 stream 转发
nginx从1.9.0开始,新增加了一个stream模块,用来实现四层协议的转发.代理或者负载均衡等. (1)关于stream域的模块有哪些? 目前官网上列出的第三方模块.简直就是http模块的镜像. ...
- openresty(nginx) 配置 http与https使用同一个端口,禁止 IP 直接访问
准备好工作目录 mkdir work cd work mkdir conf logs 准备好 conf/nginx.conf 配置文件, 把 your.domain 换成你自己的域名 user abc ...
- Openresty安装及使用配置(OPENRESTY+NGINX)
Openresty 简介 Openresty是一个基于NGINX和Lua的高性能Web平台,内部有大量的Lua库和第三方模块,能够很方便的搭建处理高并发,扩展性高的Web平台和动态网关,充分利用 Ng ...
- centos8上配置openresty/nginx可访问php
一,创建一个测试站的目录 [root@yjweb data]# mkdir dev [root@yjweb data]# cd dev [root@yjweb dev]# mkdir think_ww ...
- 使用etcd+confd管理nginx配置
1.前言 最近在项目中用nginx做反向代理,需要动态生成nginx的配置.大概流程是用户在页面上新增域名.http或https协议以及端口信息,后台会根据域名自动生成一个nginx的server配置 ...
- OpenResty(nginx+lua) 入门
OpenResty 官网:http://openresty.org/ OpenResty 是一个nginx和它的各种三方模块的一个打包而成的软件平台.最重要的一点是它将lua/luajit打包了进来, ...
- openresty(nginx)、lua、drizzle调研
一.概述: 1.研究目标:nginx中使用lua脚本,及nginx直接访问mysql,redis 2.需要安装的内容: openresty,mysql,redis 3.OpenResty (也称为 n ...
- OpenResty(nginx扩展)实现防cc攻击
OpenResty(nginx扩展)实现防cc攻击 导读 OpenResty 通过汇聚各种设计精良的 Nginx 模块(主要由 OpenResty 团队自主开发),从而将 Nginx 有效地变成一个强 ...
- openresty nginx 安装过程记录
转载请注明原始地址 http://www.cnblogs.com/dongxiao-yang/p/4877799.html 一 :系统版本 1 cat /etc/issue: CentOS relea ...
随机推荐
- Wordpress学习链接整理
Wordpress学习链接整理 获取和使用 WordPress 中的全局变量 wordpress模板加载顺序汇总 WordPress载入页面时的模板加载机制(图) WordPress 条件判断标签及用 ...
- 【ShardingSphere】ShardingSphere学习(二)-核心概念-SQL
逻辑表 水平拆分的数据库(表)的相同逻辑和数据结构表的总称. 例:订单数据根据主键尾数拆分为10张表,分别是t_order_0到t_order_9,他们的逻辑表名为t_order. 真实表 在分片的数 ...
- Windows核心编程 第八章 用户方式中线程的同步(上)
第8章 用户方式中线程的同步 当所有的线程在互相之间不需要进行通信的情况下就能够顺利地运行时, M i c r o s o f t Wi n d o w s的运行性能最好.但是,线程很少能够在所有的时 ...
- 大事件,Java被超越了,2021年5月TIOBE编程语言排行榜出炉
TIOBE 头条 TIOBE 5月编程语言排行榜新鲜出炉.前十榜单中,C.Python.Java三大鳌头仍占据前三榜单.去年11月,Python短时间的挤掉Java跃居至榜单第二名:今年5月,Pyth ...
- 【Unity】实验二 游戏场景搭建
实验要求 实验二 游戏场景搭建 实验目的:掌握游戏场景搭建. 实验要求:能够使用Unity的地形引擎创建地形,熟悉场景中的光照与阴影,掌握天空盒和雾化效果等. 实验内容: 地形的绘制:使用高度图绘制: ...
- Arduino+DS18b20+OLED Display
DS18b20获取到温度数值保存到变量中,然后和天气图标还有滚动字幕一起发送到OLED 屏幕上显示 需要用到的库均可在Arduino库管理器下载. 电路图: 图中屏幕接线已在代码中写出,温度传感器da ...
- idea设置js为ES6
- python通过字符串定义函数名
记录python里的一个有意思的小技巧:通过字符串定义函数名称. import sys m=sys.modules[__name__] def temp(x): return x+1 setattr( ...
- 前端基础问题:CSS vertical-align 属性
CSS vertical-align 属性与基线的那些事~ 定义和用法: vertical-align 属性设置元素的垂直对齐方式. vertical-align只对内联元素(inline.inlin ...
- 标签页切换title改变
js实现如下 并将代码加入博客侧边栏就成了 <script> document.addEventListener("visibilitychange", functio ...