openresty

Lua: How to gzip a string (gzip, not zlib) in memory?

不羁的心 提交于 2019-12-25 10:00:00
问题 Given a string, how can I compress it in memory with gzip? I'm using Lua. It sounds like an easy problem, but there is a huge list of libraries. So far, all that I tried were either dead or I could produce only zlib compressed strings. In my use case, I need gzip compression, as it is expected by the receiver. As a test, if you dump the compressed string to a file, zcat should be able to decompress it. I'm using OpenResty, so any Lua library should be fine. (The only solution that I got

Lua: How to gzip a string (gzip, not zlib) in memory?

故事扮演 提交于 2019-12-25 09:58:22
问题 Given a string, how can I compress it in memory with gzip? I'm using Lua. It sounds like an easy problem, but there is a huge list of libraries. So far, all that I tried were either dead or I could produce only zlib compressed strings. In my use case, I need gzip compression, as it is expected by the receiver. As a test, if you dump the compressed string to a file, zcat should be able to decompress it. I'm using OpenResty, so any Lua library should be fine. (The only solution that I got

ELK 之前端 nginx+elasticsearch+ kibana 部署

别等时光非礼了梦想. 提交于 2019-12-24 16:08:47
之前有导读部分内容,介绍了elk的及kafka的前世今生及优点,各位客官可以点击这里访问,欢迎大家批评指正交流学习共同进步; ( https://blog.51cto.com/seekerwolf/2085891 ) OS:Centos 7 ELK Stack : 6.2.2 安装方式:源码安装 我的日志收集系统是基于这样的架构来做,前端代理使用Nginx,然后是ELK 的全家桶,文件收集使用filebeat来搞定; 一,系统优化, 在安装ES 的主机上需要作如下系统级别的优化工作,不然启动ElasticSearch 的时候会出现报错,同时给未来的运维工作也埋下隐患,所以一开始做好优化之后,以后就不会被各种怪异问题缠绕了! #最大文件打开数参数优化: max file open file-max的含义。man proc,可得到file-max的描述: This file defines a system-wide limit on the number of open files for all processes. (See also setrlimit(2), which can be used by a process to set the per-process limit, RLIMIT_NOFILE, on the number of files it may open

国内加速下载镜像地址

☆樱花仙子☆ 提交于 2019-12-22 22:39:42
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 国内直接从官网下载比较困难,需要一些技术手段。这里提供一个国内的镜像下载地址列表,方便网友下载。 Zabbix Yarn Selenium Redis RabbitMQ Python Phantomjs Phantomjs POI Openresty Openjdk Nodejs Nginx MySQL Memcached Leveldown Keepalived Helm HAProxy Grafana Git for MacOS GeckoDriver Filebeat Etcd Electron ChromeDriver Bazel Ansible Tortoisegit Logstash Kibana Elasticsearch Git for Windows 来源: oschina 链接: https://my.oschina.net/newbe36524/blog/3146008

How come I cannot set multiple cookies

萝らか妹 提交于 2019-12-22 10:53:32
问题 I'm trying to set multiple cookies, but it's not working: if type(ngx.header["Set-Cookie"]) ~= "table" then ngx.header["Set-Cookie"] = {} end table.insert(ngx.header["Set-Cookie"], "Cookie1=abc; Path=/") table.insert(ngx.header["Set-Cookie"], "Cookie2=def; Path=/") table.insert(ngx.header["Set-Cookie"], "Cookie3=ghi; Path=/") On the client I do not receive any cookies. 回答1: ngx.header["Set-Cookie"] is a special table, and must be reassigned to with a new table every time you modify it

API接口访问频次限制 / 网站恶意爬虫限制 / 网站恶意访问限制 方案

柔情痞子 提交于 2019-12-20 20:55:17
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> API接口访问频次限制 / 网站恶意爬虫限制 / 网站恶意访问限制 方案 采用多级拦截,后置拦截的方式体系化解决 1 分层拦截 1.1 第一层 商业web应用防火墙(WAF) 直接用商业服务 传统的F5硬件,不过现在用的很少了 云时代就用云时代的产品,典型代表 阿里云 web应用防火墙 1.2 第二层 API 网关(API Gateway)层 API 网关(API Gateway) kong为代表的开源 API 网关 实现 openresty + lua 自实现 windows平台 安全狗、云锁 实现 1.3 第三层 应用层 用Redis内置lua脚本 redis是块砖,哪里需要哪里搬 redis内置了lua引擎,2.6版本后你可以编写一段lua脚本,完成逻辑判断流程 常见的有对某维度计数器法 对某维度令牌桶法 维度的概念比如就是IP或者IP+模块等, 多个字段合并成一个维度 本方案满足绝大多数应用层的限流需求 当然也可以自己用应用层程序实现,前提是redis+lua满足不了你的需求 2 后置拦截 基本的套路其实很简单,从日志这里计算出恶意IP,恶意用户,再给其他系统用 分控的基本思想也是这样的 已经在用ELK日志系统:可以用ES中定时查询高频IP,送入WAF做拦截 已经在用流计算系统

openresty 前端开发入门五之Mysql篇

五迷三道 提交于 2019-12-18 01:41:22
openresty 前端开发入门五之Mysql篇 这章主要演示怎么通过lua连接mysql,并根据用户输入的name从mysql获取数据,并返回给用户 操作mysql主要用到了lua-resty-mysql库,代码可以在 github 上找得到 而且上面也有实例代码 由于官网给出的例子比较基本,代码也比较多,所以我这里主要介绍一些怎么封装一下,简化我们调用的代码 lua/mysql.lua local mysql = require "resty.mysql" local config = { host = "localhost", port = 3306, database = "mysql", user = "root", password = "admin" } local _M = {} function _M.new(self) local db, err = mysql:new() if not db then return nil end db:set_timeout(1000) -- 1 sec local ok, err, errno, sqlstate = db:connect(config) if not ok then return nil end db.close = close return db end function close(self)

Token ,Cookie、Session傻傻分不清楚?

一曲冷凌霜 提交于 2019-12-17 09:19:00
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 作者 | 王菜鸟1993 来源 | cnblogs.com/JamesWang1993/p/8593494.html 在做接口测试时,经常会碰到请求参数为token的类型,但是可能大部分测试人员对token,cookie,session的区别还是一知半解。 Cookie cookie 是一个非常具体的东西,指的就是浏览器里面能永久存储的一种数据,仅仅是浏览器实现的一种数据存储功能。 <span style="color:red;">cookie由服务器生成,发送给浏览器,浏览器把cookie以kv形式保存到某个目录下的文本文件内,下一次请求同一网站时会把该cookie发送给服务器。</span>由于cookie是存在客户端上的,所以浏览器加入了一些限制确保cookie不会被恶意使用,同时不会占据太多磁盘空间,所以每个域的cookie数量是有限的。 Session session 从字面上讲,就是会话。这个就类似于你和一个人交谈,你怎么知道当前和你交谈的是张三而不是李四呢?对方肯定有某种特征(长相等)表明他就是张三。 session 也是类似的道理,服务器要知道当前发请求给自己的是谁。为了做这种区分,<span style="color:red;">服务器就要给每个客户端分配不同的“身份标识”

openresty的安装及使用基于CentOS

人盡茶涼 提交于 2019-12-13 22:35:10
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 【yum安装】 (网速的原因,可能会失败,多试几次) #yum install yum-utils #yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo #yum install openresty 默认会安装到/usr/local/openresty/ 这个目录下 **************yum方式安装至此完*************** 【配置账号密码登录auth_basic_user_file】 用htpasswd 生成登录秘钥文件: # htpasswd -bc pw.db aaa bbb 用户名为aaa密码为bbb生成的秘钥文件为pw.db nginx中配置如下,见auth_basic部分: location / { root html; index index.html index.htm; auth_basic "secure1"; auth_basic_user_file /usr/local/openresty/nginx/pw.db; } #/usr/local/openresty/nginx/sbin/nginx -t #/usr/local/openresty/nginx

nginx+lua+redis(openresty)配置

拜拜、爱过 提交于 2019-12-13 22:16:34
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> nginx+lua+redis(openresty)配置 2014-07-18 11:10 2494人阅读 评论 (1) 收藏 举报 方案一: 1.安装lua解释器 wget http://luajit.org/download/LuaJIT-2.0.2.tar.gz (http://luajit.org/download.html) 配置lua Lib和include/luajit-$version目录为环境变量 2.下载ngx_devel_kit和lua-nginx-module https://codeload.github.com/simpl/ngx_devel_kit/tar.gz/v0.2.19 ( https://github.com/simpl/ngx_devel_kit/tags) https://codeload.github.com/openresty/lua-nginx-module/tar.gz/v0.9.10 (https://github.com/openresty/lua-nginx-module/tags) 3.安装配置nginx http://nginx.org/download/nginx-1.4.7.tar.gz (http://nginx.org/en/download