02-OpenResty Hello World

一、First Hello World

PS :OpenResty官方参考文档 http://openresty.org/en/getting-started.html
PS : ngx lua 官方参考文档 https://www.nginx.com/resources/wiki/modules/lua

1.1、Nginx 配置准备

worker_processes  1;
error_log logs/error.log;
events {
    worker_connections 1024;
}
http {
    server {
        listen 8080;
        location /hello {
            default_type text/html;
            content_by_lua_block {
                ngx.say("<p>hello, world</p>")
            }
        }
    }
}

1.2、访问测试

# systemctl restart openresty
# curl 127.0.0.1/hello
	<p>hello, world</p>

二、Second Hello World

2.1、nginx conf - content_by_lua_file

# 使用 content_by_lua_file 指定 lua 脚本文件地址

        location /hello {
            content_by_lua_file lua/hello.lua;
        }

2.2、hello.lua

openresty/nginx# cat lua/hello.lua 
--
-- Created by IntelliJ IDEA.
-- User: daizhe
-- Date: 2021/5/18
-- Time: 22:01
-- To change this template use File | Settings | File Templates.

ngx.say('hello world')

2.3、访问测试

# systemctl restart openresty
# curl 127.0.0.1/hello
	hello, world

三、调试阶段可以使用lua-code-cache,直接生效ngx配置

    server {
        listen       80;
        # server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        lua-code-cache off;

        location / {
            root   html;
            index  index.html index.htm;
	    limit_req zone=contentRatelLimit;
        }
posted @ 2021-05-18 21:25  SRE运维充电站  阅读(78)  评论(0编辑  收藏  举报