[nginx] OpenResty & Lua,


OpenResty是一个基于 Nginx 与 Lua 的高性能 Web 平台,
其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。
用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。

1. 安装OpenResty

$ brew install homebrew/nginx/openresty

OpenResty安装目录:/usr/local/Cellar/openresty/1.11.2.5/
nginx路径:/usr/local/Cellar/openresty/1.11.2.5/nginx/sbin/nginx
配置文件路径:/usr/local/etc/openresty/nginx.conf

2. 修改环境变量

打开~/.zshrc,在末尾加上,

export PATH=/usr/local/Cellar/openresty/1.11.2.5/nginx/sbin:$PATH

然后执行source命令,重新载入~/.zshrc

$ source ~/.zshrc

3. 新建站点

test-openresty
├── conf
│   └── nginx.conf
└── logs

其中,./conf/nginx.conf内容如下,

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

4. 启动nginx

在站点根目录下,启动nginx,

$ nginx -p `pwd`/ -c conf/nginx.conf

其中,-p用来设置路径前缀,

-p prefix     : set prefix path (default: /usr/local/Cellar/openresty/1.11.2.5/nginx/)

-c用来设置配置文件的文件名

-c filename   : set configuration file (default: /usr/local/etc/openresty/nginx.conf)

注:
(1)pwd是shell变量,表示当前目录,

$ echo `pwd`
/Users/.../test-nginx

(2)如果nginx已经启动了,则需要重新加载配置文件,

$ nginx -s reload

5. 浏览器访问

使用浏览器打开,http://localhost:8080/,显示hello


参考

OpenResty

相关内容

    暂无相关文章