windows下安装openresty_lua的开发环境

windows下安装openresty

  1. 打开openresty的中文官网,下载网站为:http://openresty.org/cn/download.html 。具体如下图
    在这里插入图片描述

  2. 启动nginx:cmd命令行,进入nginx根目录,执行start nginx

  3. 修改nginx配置文件nginx.conf 端口 listen 8888

  4. 执行 nginx -s reload 重新加载配置文件,访问路径即为http://localhost:8888

    相关命令:

    nginx -s stop 停止

    nginx -s quit 退出

    tasklist /fi “imagename eq nginx.exe” 查看进程

    taskkill /pid 5488 /F 强制杀死指定pid的进程

nginx常用命令说明

在Windows平台安装好Openresty并且设置好path环境变量之后,就可以启动Openresty了。 Openresty的原始启动命令为Nginx,其参数大致有-v、-t、-p、-c、-s等,大致的使用说明如下

  1. -v : 表示查看nginx版本

    D:\Program Files\openresty-1.19.9.1-win64>nginx -v
    nginx version: openresty/1.19.9.1
    
  2. -c:指定一个新的Nginx配置文件来替换默认的Nginx配置文件。

    D:\Program Files\openresty-1.19.9.1-win64>nginx -p ./ -c nginx-debug.conf
    
  3. -t:表示测试Nginx的配置文件。如果不能确定Nginx配置文件语法是否正确,你可以通过 Nginx命令-t参数来测试。此参数代表不运行配置文件,而仅仅只是测试配置文件。

    D:\Program Files\openresty-1.19.9.1-win64> nginx -t -c nginx-debug.conf 
    nginx: the configuration file ./nginx-debug.conf syntax is ok 
    nginx: configuration file ./nginx-debug.conf test 
    
  4. -p:表示设置前缀路径

    D:\Program Files\openresty-1.19.9.1-win64>nginx -p ./ -c nginx-debug.conf
    

    上面的命令中," -p ./ “表示将当前目录” D:\Program Files\openresty-1.19.9.1-win64"作为前缀路径,也就是 说,nginx-debug.conf配置文件中所用到的相对路径都加上这个前缀。

  5. -s:表示给Nginx进程发送信号,包含:stop(停止)、reload(重写加载)。

    //重启Nginx进程,发送reload信号
    D:\Program Files\openresty-1.19.9.1-win64> nginx -p ./ -c nginx-debug.conf -s reload 
    //停止nginx进程,发送stop信号 
    D:\Program Files\openresty-1.19.9.1-win64> nginx -p ./ -c nginx-debug.conf -s stop
    

lua开发环境搭建

idea + emmy lua插件

  1. 下载lua sdk

下载路径:http://luabinaries.sourceforge.net/
在这里插入图片描述

  1. 配置lua sdk
    在这里插入图片描述在这里插入图片描述

  2. 创建hello world
    在这里插入图片描述
    创建HelloLua.lua文件,编写helloworld语句

print("hello world")
  1. 配置lua运行环境

run -> Edit Configurations; 修改 program 选择下载的sdk运行程序

在这里插入图片描述

  1. 右键lua文件->run

  2. 配置openresty运行环境新建conf目录nginx.conflogs目录

在这里插入图片描述

  • nginx.conf
worker_processes  2;
error_log  logs/error.log  info;
events {
    worker_connections  1024;
}
http {
    default_type  application/octet-stream;
    access_log  logs/access.log;
    lua_package_path 'src/?.lua;;';
    server {
        listen       10000;
        server_name  localhost;
        default_type text/html;
        location = /favicon.ico {
            log_not_found off;
            access_log off;
        }

        location /test {
            content_by_lua_file src/HelloLua.lua;
        }
    }
}
  1. 改写HelloLua.lua文件

    local function main()
        ngx.say("welcome to openresty world!")
    end
    main()
    
  2. 新建bat目录,并创建openresty启动脚本
    在这里插入图片描述

    • openresty-start.bat
    @echo off
    
    rem 启动标志 flag=0 表示之前已经启动   flag=1 表示现在立即启动
    set flag=0
    
    rem 设置 openresty/nginx的安装目录
    set installPath=D:/Program Files/openresty-1.19.9.1-win64
    
    rem 设置 Nginx 项目的工作目录
    set projectPath=D:/ideawork/hellolua
    
    rem 设置 项目的配置文件
    set PROJECT_CONF=nginx.conf
    
    echo installPath: %installPath%
    echo project prefix path: %projectPath%
    echo config file: %projectPath%/conf/%PROJECT_CONF%
    echo openresty starting.....
    
    rem 查找openresty/nginx进程信息,然后设置flag标志位
    tasklist|find /i "nginx.exe" > nul
    if %errorlevel%==0 (
    echo "openresty/nginx already running ! "
    rem exit /b
    ) else set flag=1
    
    rem 如果需要,则启动 openresty/nginx 
    rem -p指定前缀路径,-c指定nginx配置文件
    
    if %flag%==1 (
    start nginx.exe -p "%projectPath%" -c "%projectPath%/conf/%PROJECT_CONF%"
    ping localhost -n 2 > nul
    )
    
    rem 输出openresty/nginx的进程信息
    tasklist /fi "imagename eq nginx.exe"
    tasklist|find /i "nginx.exe" > nul
    if %errorlevel%==0 (
    echo "openresty/nginx  starting  succeced!"
    )
    
    • openresty-restart.bat

      @echo off
      call openresty-stop.bat
      call openresty-start.bat
      
    • openresty-status.bat

      @echo off
      tasklist|find /i "nginx.exe" > nul
      if %errorlevel%==0 (
      tasklist /fi "imagename eq nginx.exe"
      echo "openresty/nginx is running!"
      exit /b
      ) else echo "openresty/nginx is stoped!" 
      
    • openresty-stop.bat

      @echo off
      tasklist|find /i "nginx.exe"  > nul
      if  %errorlevel%==0 (
          taskkill /f /t /im nginx.exe > nul
          echo "openresty/nginx stoped!"
      )else echo "openresty/nginx not running!"
      
  3. 配置openresty环境变量(支持脚本中可以找到nginx命令)
    高级环境变量里配置path添加地址
    在这里插入图片描述

  4. 安装Batch Scripts Supports插件(idea中运行bat文件)

  5. 右键openresty-start.bat运行脚本

    在这里插入图片描述

  6. 浏览器访问localhost:10000/test,返回lua执行结果

在这里插入图片描述

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值