OpenResty第二篇:nginx+lua+openresty 实例

nginx+lua+openresty 实例

1、在http部分添加如下配置

lua模块路径,多个之间”;”分隔,其中”;;”表示默认搜索路径,默认到/usr/servers/nginx下找

lua_package_path “/usr/servers/lualib/?.lua;;”; #lua 模块
lua_package_cpath “/usr/servers/lualib/?.so;;”; #c模块

2、在nginx.conf中的http部分添加include lua.conf包含此文件片段
Java代码 收藏代码
include/usr/servers/example/lua.conf;

在/usr/server/nginx/conf下
vim lua.conf

#lua.conf  
server {  
    listen       80;  
    server_name  _;  
    
    location /lua {  
    	default_type 'text/html';  
        content_by_lua 'ngx.say("hello world")';  
    } 
}  

将Lua项目化:

mkdir /usr/example
cp -r /usr/servers/lualib/ /usr/example/
mkdir /usr/example/lua
cd /usr/example
vim example.conf
server {  
    listen       80;  
    server_name  _;  
      
    location /lua {  
        default_type 'text/html';  
        lua_code_cache off;  
        content_by_lua_file /usr/example/lua/test.lua;  
    }  
} 

vim /usr/example/lua/test.lua

ngx.say("hello world");  
cd /usr/servers/nginx/conf/
vim nginx.conf

http模块:

http {
    include       mime.types;
    default_type  application/octet-stream;
    lua_package_path "/usr/example/lualib/?.lua;;";  #lua 模块  
    lua_package_cpath "/usr/example/lualib/?.so;;";  #c模块   
    include /usr/example/example.conf;
 ....
 ....
}

nginx -s reload
浏览器访问: http://192.168.100.65/lua

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值