首页 > 使用教程 > lua gg游戏修改器_gg修改器lua脚本代码
lua gg游戏修改器_gg修改器lua脚本代码
  • gg游戏修改器免root版

  • 大小:10.10MB 版本:v1.28
  • 语言:简体中文系统:Android
无病毒 免积分 免充值

lua gg游戏修改器_gg修改器lua脚本代码

作者:佚名 来源:网友分享 发布日期:2024-4-25 06:13:41

各位游戏大佬大家好,今天小编为大家分享关于lua gg游戏修改器_gg修改器lua脚本代码的内容,轻松修改游戏数据,赶快来一起来看看吧。

1、Nginx 简介

(8)post-access

访问权限检查提交阶段;

(9)try-files

配置项try_files处理阶段;

(10)content

内容产生阶段,是所有请求处理阶段中最为重要的阶段,因为这个阶段的指令通常是用来生成HTTP响应内容的;

(11)log

日志模块处理阶段;

图:Nginx 模块执行顺序与阶段

4、ngx_lua 运行指令

ngx_lua属于nginx的一部分,它的执行指令都包含在nginx的11个步骤之中了,相应的处理阶段可以做插入式处理,即可插拔式架构,不过ngx_lua并不是所有阶段都会运行的;另外指令可以在http、server、server if、location、location if几个范围进行配置:

指令

所处处理阶段

使用范围

解释

init_by_lua

init_by_lua_file

loading-config

http

nginx Master进程加载配置时执行;

通常用于初始化全局配置/预加载Lua模块

init_worker_by_lua

init_worker_by_lua_file

starting-worker

http

每个Nginx Worker进程启动时调用的计时器,如果Master进程不允许则只会在init_by_lua之后调用;

通常用于定时拉取配置/数据,或者后端服务的健康检查

set_by_lua

set_by_lua_file

rewrite

server,server if,location,location if

设置nginx变量,可以实现复杂的赋值逻辑;此处是阻塞的,Lua代码要做到非常快;

rewrite_by_lua

rewrite_by_lua_file

rewrite tail

http,server,location,location if

rrewrite阶段处理,可以实现复杂的转发/重定向逻辑;

access_by_lua

access_by_lua_file

access tail

http,server,location,location if

请求访问阶段处理,用于访问控制

content_by_lua

content_by_lua_file

content

location,location if

内容处理器,接收请求处理并输出响应

header_filter_by_lua

header_filter_by_lua_file

output-header-filter

http,server,location,location if

设置header和cookie

body_filter_by_lua

body_filter_by_lua_file

output-body-filter

http,server,location,location if

对响应数据进行过滤,比如截断、替换。

log_by_lua

log_by_lua_file

log

http,server,location,location if

log阶段处理,比如记录访问量/统计平均响应时间

关于这部分详细可以参考这篇:

Refer

Refer

5、安装 tengine 以及 Lua 扩展

(1)先安装Nginx需要的一些类库:

yum install gcc

yum install gcc-c++

注:此步骤只是在你的系统没有安装 gcc/gcc-c++ 的情况下才需要自行编译安装。

(2)编译安装库LuaJit-2.0.3:

./configure –prefix=/usr/local/luajit

make PREFIX=/usr/local/luajit

make install PREFIX=/usr/local/luajit

在/etc/profile文件中增加环境变量,并执行 source /etc/profile 使之生效(非必须):

export LUAJIT_LIB=/usr/install/luajit/lib

export LUAJIT_INC=/usr/install/luajit/include/luajit-2.0

注:此步骤只是在你的系统没有安装 LuaJIT 的情况下才需要自行编译安装。

(3)下载模块依赖 pcre-8.34、zlib-1.2.8、ngx_devel_kit 和 lua-nginx-module,最后编译Nginx:

完整的参数可能这样:

nginx -V
Tengine version: Tengine/2.1.0 (nginx/1.6.2)
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)
TLS SNI support enabled
configure arguments: –prefix=/etc/nginx/ –sbin-path=/usr/sbin/nginx –conf-path=/etc/nginx/nginx.conf –error-log-path=/var/log/nginx/error.log –http-log-path=/var/log/nginx/access.log –pid-path=/var/run/nginx.pid –lock-path=/var/run/nginx.lock –http-client-body-temp-path=/var/cache/nginx/client_temp –http-proxy-temp-path=/var/cache/nginx/proxy_temp –http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp –http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp –http-scgi-temp-path=/var/cache/nginx/scgi_temp –user=nginx –group=nginx –with-http_ssl_module –with-http_realip_module –with-http_addition_module –with-http_sub_module –with-http_dav_module –with-http_flv_module –with-http_mp4_module –with-http_gzip_static_module –with-http_random_index_module –with-http_secure_link_module –with-http_stub_status_module –with-mail –with-mail_ssl_module –with-file-aio –with-ipv6 –with-cc-opt=’-O2 -g -m64 -mtune=generic’ –with-pcre=../pcre-8.33 –with-zlib=../zlib-1.2.8 –with-openssl=../openssl-1.0.1l

先 ./configure 各种配置参数以及模块路径,但我这里只是用来测试就精简了不少参数:

./configure –prefix=/opt/soft/nginx –with-pcre=/root/soft/pcre-8.37 –with-zlib=/root/soft/zlib-1.2.8 –with-openssl=/root/soft/openssl-1.0.1p –add-module=/root/soft/lua-nginx-module-master –add-module=/root/soft/ngx_devel_kit-master –sbin-path=/usr/sbin/nginx –conf-path=/etc/nginx/nginx.conf –error-log-path=/var/log/nginx/error.log –http-log-path=/var/log/nginx/access.log –pid-path=/var/run/nginx.pid –lock-path=/var/run/nginx.lock –http-client-body-temp-path=/var/cache/nginx/client_temp –http-proxy-temp-path=/var/cache/nginx/proxy_temp –http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp –http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp –http-scgi-temp-path=/var/cache/nginx/scgi_temp

然后 make、make install 即可。

(5)启动Nginx sbin/nginx,浏览器输入http://localhost测试

需要注意的是:

(1)–with-pcre=/root/soft/pcre-8.37 –with-zlib=/root/soft/zlib-1.2.8 指向的是源码路径,而非编译后的路径,否则 make 会报:

cd /usr/local/pcre
&& if [ -f Makefile ]; then make distclean; fi
&& CC=”gcc” CFLAGS=”-O2 -fomit-frame-pointer -pipe ”
./configure –disable-shared
/bin/sh: ./configure: No such file or directory
make[1]: *** [/usr/local/pcre/Makefile] Error 127
make[1]: Leaving directory `/software/nginx-0.8.53’
make: *** [build] Error 2

因为 ./configure –help 看一下帮助说明:

–with-pcre=DIR set path to PCRE library sources

set path to PCRE library sources 是让你设置到源码目录,而不是编译安装后的目录

(2)pcre、zlib、openssl 等系统库如果系统没有集成自带,一定要单独编译安装,而 lua-nginx-module、ngx_devel_kit 等插件模块只需要指源码路径给 nginx 一起编译即可,不需要单独编译。

6、一个 Nginx + Lua 测试的例子

user work work;worker_processes 7;error_log /opt/data1/logs/nginx/error.log;pid /var/run/nginx.pid;worker_rlimit_nofile 800000;events { use epoll; worker_connections 65535;
}http {
server { listen 80; set $idTest “idTest_11111111111″ ; log_format tracklog ’$idTest $msec $remote_addr – $remote_user [$time_local] $request ’
’”$status” resp_body:”$resp_body” –“$ref1”– ’
’”$http_user_agent”’;
location ~ /gzip/(.*) { default_type “text/html”;
set $resp_body “”; content_by_lua ’
–zlib 解码 post gzip 数据
local zlib = require “zlib”
local encoding = ngx.req.get_headers()[“Content-Encoding”]

if encoding == “gzip” then
ngx.req.read_body()
local body = ngx.req.get_body_data()
ngx.say(“++++++++++++++++++++++++++++body data:”)
ngx.print(body)
if body then
–ngx.var.resp_body = “55555555555555”
local stream = zlib.inflate()
ngx.var.resp_body = stream(body)
end
end
’;
access_log on; access_log /opt/data1/logs/nginx/pc/track/.access.log tracklog;
} location ~ /post/(.*) { default_type “text/html”; lua_need_request_body on;
set $resp_body “”; content_by_lua ’
ngx.var.resp_body = ngx.var.request_body
’;
access_log on; access_log /opt/data1/logs/nginx/pc/track/.access.log tracklog;
}

location ~ /lua/(.*) { default_type “text/html”;
set $ref1 “Hello,Nginx & Lua !”;
#设置nginx变量
set $a $1;
set $b $host;
content_by_lua ’
–nginx变量
local var = ngx.var
ngx.say(“ngx.var.a : “, var.a, “<br/>”)
ngx.say(“ngx.var.b : “, var.b, “<br/>”)
ngx.say(“ngx.var[2] : “, var[2], “<br/>”)
ngx.var.b = 2;
ngx.say(“<br/>”)

–请求头
ngx.say(ngx.var.httpRef, “<br/>”)
local headers = ngx.req.get_headers()
for k,v in pairs(headers) do
if type(v) == “table” then
ngx.say(k, ” : “, table.concat(v, “,”), “<br/>”)
else
ngx.say(k, ” : “, v, “<br/>”)
end
end
ngx.say(“————headers end———–“, “<br/><br/><br/>”)

–get请求uri参数
ngx.say(“uri args begin”, “<br/>”)
local uri_args = ngx.req.get_uri_args()
for k, v in pairs(uri_args) do
if type(v) == “table” then
ngx.say(k, ” : “, table.concat(v, “, “), “<br/>”)
else
ngx.say(k, “: “, v, “<br/>”)
end
end
ngx.say(“uri args end”, “<br/>”)
ngx.say(“a: “,ngx.var.arg_a, “<br/>”)
ngx.say(“b: “,ngx.var.arg_b, “<br/>”)

–未经解码的请求 uri
local request_uri = headers[“Host”] .. “/” .. ngx.var.request_uri;
ngx.say(“request_uri : “, request_uri, “<br/>”);
–解码后的 uri
local decode_request_uri = headers[“Host”] .. “/” .. ngx.unescape_uri(ngx.var.request_uri);
ngx.var.ref1 = decode_request_uri;
ngx.say(“decode request_uri : “, decode_request_uri, “<br/>”);
–MD5
ngx.say(“ngx.md5 : “, ngx.md5(“123”), “<br/>”)
–http time
ngx.say(“ngx.http_time : “, ngx.http_time(ngx.time()), “<br/>”)
–ngx.var.http_referer = “*********************”

’;

log_format LogFormatv1 ’$idTest@$msec@$remote_addr@-@$remote_user@[$time_local]@$request@’
’”$status”@$body_bytes_sent@”$http_referer”@’
’”$http_user_agent”’;
access_log on; access_log /opt/data1/logs/nginx/PCv1/track/.access.log LogFormatv1;
}

}
}

需要注意的是线上的 Nginx 可能面对的是高并发场景,对于自己的 Lua 代码最好做个压力测试,比如:

tcpcopy

或者

ab -c100 -n10000 ’http://test./lua/test%20haha/?a=3&b=4’

7、关于 64bit Cgywin 下编译安装 Tengine 的一些问题

(1)openSSL 库不支持 64bit Cygwin

cryptlib.c:1:0: 错误:您选择的 CPU 不支持 x86-64 指令集
/* crypto/cryptlib.c */ ^
cryptlib.c:1:0: 错误:您选择的 CPU 不支持 x86-64 指令集
<builtin>: recipe for target ’cryptlib.o’ failed
make[3]: *** [cryptlib.o] Error 1make[3]: Leaving directory ’/home/Jun/softs/openssl-1.0.1r/crypto’Makefile:281: recipe for target ’build_crypto’ failed

这种要么自己去网上找补丁 patch,要么换成 Cygwin 32bit,还有一种解决方案就是自己在安装 Cygwin 包的时候把 openssl 也装上,也就是说选择安装包的时候尽量装全一点。省得后续自己装遇到各种问题。

这样如果你自己已经装了 openssl 那么可以在configure 的时候去掉openssl 相关的编译依赖选项:

./configure –with-openssl=/root/soft/openssl-1.0.1p (去掉该项)

(2)nginx 启动报错:

nginx: [emerg] the maximum number of files supported by select() is 64

毕竟 Cygwin 还是依赖 windows的,各种参数得针对 windows 优化,比如这个报错是说默认配置文件里的 worker_connections 不能超过 64 个,你改成 20 即可。

events {
use epoll;
worker_connections 65535;
}

比如我这里的编译配置参数是(注意有些目录可能需要提前自己创建):

./configure –prefix=/opt/soft/nginx –with-pcre=/home/Jun/softs/pcre-8.38 –with-zlib=/home/Jun/softs/zlib-1.2.8 –add-module=/home/Jun/softs/ngx_devel_kit-master –add-module=/home/Jun/softs/echo-nginx-module-master –add-module=/home/Jun/softs/form-input-nginx-module-master –add-module=/home/Jun/softs/set-misc-nginx-module-master –add-module=/home/Jun/softs/lua-nginx-module-master –sbin-path=/usr/sbin/nginx –conf-path=/etc/nginx/nginx.conf –error-log-path=/var/log/nginx/error.log –http-log-path=/var/log/nginx/access.log –pid-path=/var/run/nginx.pid –lock-path=/var/run/nginx.lock –http-client-body-temp-path=/var/cache/nginx/client_temp –http-proxy-temp-path=/var/cache/nginx/proxy_temp –http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp –http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp –http-scgi-temp-path=/var/cache/nginx/scgi_temp

最后 nginx.conf 稍加修改如下(注意有些目录可能需要提前自己创建):

worker_processes 2;
#error_log /var/log/nginx/error.log;pid /var/run/nginx.pid;
events {
worker_connections 20;
}
http {

server {
listen 80;

set $idTest “idTest_11111111111″ ;

log_format tracklog ’$idTest $msec $remote_addr – $remote_user [$time_local] $request ’ ’”$status” $body_bytes_sent –“$ref1”– ’ ’”$http_user_agent”’;

log_format LogFormatv1 ’$idTest@$msec@$remote_addr@-@$remote_user@[$time_local]@$request@’ ’”$status”@$body_bytes_sent@”$http_referer”@’ ’”$http_user_agent”’;

access_log on;

location ~ /lua/(.*) {
default_type “text/html”;
set $ref1 “Hello,Nginx & Lua !”;
#设置nginx变量 set $a $1;
set $b $host;

content_by_lua ’
–nginx变量
local var = ngx.var
ngx.say(“ngx.var.a : “, var.a, “<br/>”)
ngx.say(“ngx.var.b : “, var.b, “<br/>”)
ngx.say(“ngx.var[2] : “, var[2], “<br/>”)
ngx.var.b = 2;
ngx.say(“<br/>”)

–请求头
ngx.say(ngx.var.httpRef, “<br/>”)
local headers = ngx.req.get_headers()
for k,v in pairs(headers) do
if type(v) == “table” then
ngx.say(k, ” : “, table.concat(v, “,”), “<br/>”)
else
ngx.say(k, ” : “, v, “<br/>”)
end
end
ngx.say(“————headers end———–“, “<br/><br/><br/>”)

–get请求uri参数
ngx.say(“uri args begin”, “<br/>”)
local uri_args = ngx.req.get_uri_args()
for k, v in pairs(uri_args) do
if type(v) == “table” then
ngx.say(k, ” : “, table.concat(v, “, “), “<br/>”)
else
ngx.say(k, “: “, v, “<br/>”)
end
end
ngx.say(“uri args end”, “<br/>”)
ngx.say(“a: “,ngx.var.arg_a, “<br/>”)
ngx.say(“b: “,ngx.var.arg_b, “<br/>”)

–未经解码的请求 uri
local request_uri = headers[“Host”] .. “/” .. ngx.var.request_uri;
ngx.say(“request_uri : “, request_uri, “<br/>”);
–解码后的 uri
local decode_request_uri = headers[“Host”] .. “/” .. ngx.unescape_uri(ngx.var.request_uri);
ngx.var.ref1 = decode_request_uri;
ngx.say(“decode request_uri : “, decode_request_uri, “<br/>”);
–MD5
ngx.say(“ngx.md5 : “, ngx.md5(“123”), “<br/>”)
–http time
ngx.say(“ngx.http_time : “, ngx.http_time(ngx.time()), “<br/>”)
–ngx.var.http_referer = “*********************”
’;

access_log /var/log/nginx/.access.log tracklog;
}

}
}

最后 nginx -s reload 效果如下, 请求也正常,和 linux 下结果一致:

8、关于 nginx 正则说明

(1)location 匹配语法规则

Nginx location 的正则匹配语法与优先级容易让新同学迷惑。

~ #波浪线表示执行一个正则匹配,区分大小写

~* #表示执行一个正则匹配,不区分大小写

= #进行普通字符精确匹配,与location在配置文件中的顺序无关,= 精确匹配会第一个被处理

@ #”@” 定义一个命名的 location,使用在内部定向时,例如 error_page, try_files

^~ 标识符后面跟一个字符串。表示普通字符匹配,如果该选项匹配,只匹配该选项,不匹配别的选项,Nginx将在这个字符串匹配后停止进行正则表达式的匹配(location指令中正则表达式的匹配的结果优先使用),如:location ^~ /images/,你希望对/images/这个目录进行一些特别的操作,如增加expires头,防盗链等,但是你又想把除了这个目录的图片外的所有图片只进行增加expires头的操作,这个操作可能会用到另外一个location,例如:location ~* .(gif|jpg|jpeg)$,这样,如果有请求/images/1.jpg,nginx如何决定去进行哪个location中的操作呢?结果取决于标识符^~,如果你这样写:location /images/,这样nginx会将1.jpg匹配到location ~* .(gif|jpg|jpeg)$这个location中,这并不是你需要的结果,而增加了^~这个标识符后,它在匹配了/images/这个字符串后就停止搜索其它带正则的location。

例如:

location = / { # 只匹配”/”. [ configuration A ]
}
location / { # 匹配任何请求,因为所有请求都是以”/”开始 # 但是更长字符匹配或者正则表达式匹配会优先匹配 [ configuration B ]
}
location ^~ /images/ { # 匹配任何以 /images/ 开始的请求,并停止匹配 其它location [ configuration C ]
}
location ~* .(gif|jpg|jpeg)$ { # 匹配以 gif, jpg, or jpeg结尾的请求. # 但是所有 /images/ 目录的请求将由 [Configuration C]处理. [ configuration D ]
}

请求URI例子:

= 表示精确的查找地址,如location = /它只会匹配uri为/的请求,如果请求为/index.html,将查找另外的location,而不会匹配这个,当然可以写两个location,location = /和location /,这样/index.html将匹配到后者,如果你的站点对/的请求量较大,可以使用这个方法来加快请求的响应速度。

@ 表示为一个location进行命名,即自定义一个location,这个location不能被外界所访问,只能用于Nginx产生的子请求,主要为error_page和try_files。

(2)location 优先级官方文档

  1. =前缀的指令严格匹配这个查询。如果找到,停止搜索。

  2. 所有剩下的常规字符串,最长的匹配。如果这个匹配使用^〜前缀,搜索停止。

  3. 正则表达式,在配置文件中定义的顺序。

  4. 如果第3条规则产生匹配的话,结果被使用。否则,如同从第2条规则被使用。

(3)正则语法

~ 为区分大小写的匹配。

~* 不区分大小写的匹配(匹配firefox的正则同时匹配FireFox)。

!~ 不匹配的

!~* 不匹配的

. 匹配除换行符以外的任意字符

w 匹配字母或数字或下划线或汉字

s 匹配任意的空白符

d 匹配数字

 匹配单词的开始或结束

^ 匹配字符串的开始

$ 匹配字符串的结束

W 匹配任意不是字母,数字,下划线,汉字的字符

S 匹配任意不是空白符的字符

D 匹配任意非数字的字符

B 匹配不是单词开头或结束的位置

捕获 (exp) 匹配exp,并捕获文本到自动命名的组里

(?<name>exp) 匹配exp,并捕获文本到名称为name的组里,也可以写成(?’name’exp)

(?:exp) 匹配exp,不捕获匹配的文本,也不给此分组分配组号

零宽断言 (?=exp) 匹配exp前面的位置

(?<=exp) 匹配exp后面的位置

(?!exp) 匹配后面跟的不是exp的位置

(?<!exp) 匹配前面不是exp的位置

以上就是关于lua gg游戏修改器_gg修改器lua脚本代码的全部内容,游戏大佬们学会了吗?

技能推荐

热门下载

其他人还在搜