idea搭建Lua+OpenResty+Nginx开发环境
1.下载openrestry并解压到本地:
下载地址:http://openresty.org/cn/download.html
2.安装插件:Lua,openrestyLuaSupport,idea-nginx-support
参考地址:https://blog.csdn.net/u014079773/article/details/101062867
3.配置nginx服务:
点击"OK",选择已添加的nginx
配置nginx.conf文件打开方式,设置完成之后,我们看到的nginx.conf文件中语法就高亮显示了。
到此环境配置结束,接下来测试案例:
创建一个Lua工程:
创建好后,在根目录下创建conf文件夹,build.xml文件,在conf文件夹下创建nginx.conf文件,在src目录下创建test.lua文件。整个项目结构如下:
配置文件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 'myLua/?.lua;;';
server {
listen 80;
server_name localhost;
default_type text/html;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location /test {
content_by_lua_file myLua/test.lua;
}
}
}
文件build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project name="myLua" default="dist" basedir=".">
<description>
run myLua
</description>
<!-- set global properties for this build -->
<property name="openresty-home" location="E:\openresty-1.15.8.2-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>
文件test.lua
local function main()
ngx.say("Hello World,This is my first lua!");
end;
main()
Ant build添加build.xml构建:
使用idea nginx support插件自动化构建项目,idea启动nginx
到此环境配置完成
idea启动nginx:
本地启动成功,访问test.lua:http://localhost/test
总结:
配置ant主要目的将当前项目复制到myLua路径下
build.xml主要目的配置myLua工作路径及idea工程配置文件路径
错误定位:
通常情况下nginx启动、运行出现的错误都会记录日志,在logs目录下的error.log文件可以看到日志记录,这样有利于我们排查问题。