openresty-lua相关

nginx配置参数

        proxy_pass https: //yuntongapi.websaas.cn;
        proxy_set_header Host "yuntongapi.websaas.cn";
        proxy_ssl_name "yuntongapi.websaas.cn";
        proxy_ssl_server_name on;

常用函数总结

参考链接:Nginx API for Lua

1、ngx.req.get_headers()

获取请求头函数

	local headers = ngx.req.get_headers()
	local hedhost = headers["Hostpre"]
	headers["Host"]
	headers["Referer"]
2、ngx.req.set_header()
	ngx.req.set_header("Content-Type", "text/css")
	ngx.req.set_header("Foo", {"a", "abc"})
	-------------------------------------------
	ngx.req.set_header("X-Foo", nil) 
	is equivalent to
	ngx.req.clear_header("X-Foo")
	--------------------------------------------
3、ngx.req.set_uri()

重写url函数,注意: url中存在# 时使用 ngx.redirect()

	local url = "/login/test"
	ngx.req.set_uri(lgurl)
4、ngx.req.set_uri_args()

设置 请求参数函数

    ngx.req.set_uri_args("a=test")
	ngx.req.set_uri_args("a=3&b=hello%20world")
	ngx.req.set_uri_args({ a = 3, b = "hello world" })
5、ngx.redirect()

301、302 跳转函数

	local newUrl = "https://www.baidu.com"
	ngx.redirect(newUrl)
6、ngx.log()

打印nginx的日志

	ngx.log(ngx.ERR,"log is ", ngx.var.uri)

log-level: ngx.STDERR
ngx.EMERG
ngx.ALERT
ngx.CRIT
ngx.ERR
ngx.WARN
ngx.NOTICE
ngx.INFO
ngx.DEBUG

7、ngx.resp.get_headers()

获取响应头的信息

 	local resheaders = ngx.resp.get_headers()
 	local loc = resheaders["Location"]
8、ngx.header.HEADER

设置响应头信息

	ngx.header['Set-Cookie'] = {'a=32; path=/', 'b=4; path=/'}
will yield
	Set-Cookie: a=32; path=/
	Set-Cookie: b=4; path=/
	
	-- equivalent to ngx.header["Content-Type"] = 'text/plain'
 	ngx.header.content_type = 'text/plain'
 	
 	ngx.header["X-My-Header"] = 'blah blah'
 	--------------------------------------------
 	ngx.header.content_type = {'a', 'b'}
is equivalent to
 	ngx.header.content_type = 'b'
 	----------------------------------------------
 	ngx.header["X-My-Header"] = nil
The same applies to assigning an empty table:
 	ngx.header["X-My-Header"] = {}
 	---------------------------------------------
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值