OpenResty让浏览器运行Lua(入门)

蚊子 2023年03月08日 361次浏览

简介

OpenResty是一个基于Nginx与Lua的高性能 Web 平台,目前国内有bilibili(b站)在用

环境:win10电脑本地,OpenResty版本:1.15.8.2,Lua版本:lua53

OpenResty官方最新版,没有Lua文件,这里提供的文件如下
OpenResty:https://wwba.lanzoum.com/iN4iF0plwoad
Lua53:https://wwba.lanzoum.com/iDJPQ0plwopi


开始

配置lua运行环境,不能有中文,一路保存完,才能正常配置
image-1678265178981
image-1678265206389


开始

注意:我的OpenResty安装在D盘,实际路径要看你自已

1.打开:D:\openresty-1.15.8.2-win64\conf\nginx.conf,换成你的OpenResty安装路径
image-1678265491800

2.打开D:\openresty-1.15.8.2-win64\conf\lua.conf,清空里面所有,把下面代码粘贴进去
C:/Users/yy/Desktop/test/1.lua是我测试lua文件地址,名字叫1.lua,1.lua代码请看其它(最下面)
webtest是测试方法,一会地址栏访问用到,名字可随意

ua_shared_dict my_cache 128m;

server {
	listen	9090;
	server_name	localhost;

	location / {
		root   html;
		index  index.html index.htm;
    }
	location /webtest {
		default_type text/html;
		content_by_lua_file C:/Users/yy/Desktop/test/1.lua;
    }
}

启动

1.打开你的OpenResty安装目录,我的是:D:\openresty-1.15.8.2-win64
2.双击 nginx.exe 文件,一闪而过即启动成功,也可以用命令行启动,具体参数请看其它(最下面)
3.打开浏览器,输入127.0.0.1:9090/webtest,即可看到效果
image-1678267328088

#其它
1.lua代码,lua语法学习:https://www.runoob.com/lua/lua-tutorial.html

ngx.say("你好,Lua&openresty")

2.命令行常用命令,注意:要在OpenResty安装目录内打开CMD

启动 停止 重启 强制结束进程
nginx.exe nginx.exe -s stop nginx.exe -s reload taskkill /f /t /im nginx.exe

当停止后,发现端口仍在运行,再次停止报错,就使用 强制结束进程
image-1678267780370