下载openresty
下载地址:http://openresty.org/cn/download.html
解压后如下图所示:
安装idea插件
安装Emmylua
安装nginx Support
创建lua项目
创建项目如下(注:该项目为java项目):
创建好项目后,在根目录下创建conf文件夹,在conf文件夹下创建nginx.conf文件,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;
server {
listen 8080;
server_name localhost;
default_type text/html;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location /test {
content_by_lua_file openresty_lua/test.lua;
}
}
}
在根目录下创建build.xml文件,内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<project name="openresty_lua" default="dist" basedir=".">
<description>
run openresty_lua
</description>
<!-- set global properties for this build -->
<property name="openresty-home" location="c:\code\openresty-1.27.1.1-win64"/>
<property name="conf" location="${basedir}/conf"/>
<property name="src" location="${basedir}/src"/>
<property name="target-conf" location="${openresty-home}/conf"/>
<property name="target-src" location="${openresty-home}/${ant.project.name}"/>
<echo>######开发版本的ant配置#####</echo>
<target name="clean" depends="">
<echo>清理openresty目录 ${dist}下的conf,logs,janus,januslib</echo>
<delete dir="${target-conf}"/>
<delete dir="${target-src}"/>
<delete>
<fileset dir="${openresty-home}/logs" includes="*.log"></fileset>
</delete>
</target>
<target name="init" depends="clean">
<echo>创建安装目录</echo>
<mkdir dir="${target-conf}"/>
<mkdir dir="${target-src}"/>
</target>
<target name="dist" depends="init" description="generate the distribution" >
<echo>复制安装文件</echo>
<copy todir="${target-conf}">
<fileset dir="${conf}"></fileset>
</copy>
<copy todir="${target-src}">
<fileset dir="${src}"></fileset>
</copy>
</target>
</project>
idea配置openresty环境
点击如下红框所示一步一步操作:
启动,访问http://localhost:8080如下图所示表示配置成功:
Ant构建
Ant添加build.xml:
自动构建项目
编写lua代码并运行
在src目录下创建test.lua文件,代码如下:
local function main()
ngx.say("hello")
end
main()
启动服务:
访问http://localhost:8080/test