OpenResty
OpenResty
安装(macOS)
Brew安装
brew tap openresty/brew
brew install openresty
如果要开机启动openresty,可使用命令/usr/local/opt/openresty
openresty安装目录/usr/local/opt/openresty/
手动安装
如果通过brew install openresty/brew/openresty
安装openresty失败。也可以通过源码安装
1.通过官方下载最新的源码包
2.修改压缩包中的configure
文件,添加一行$extra_opts .= " CFLAGS='-fno-stack-check'";
参考Can't install openresty on macOS 10.15
if ($platform eq 'macosx') {
my $v = $ENV{MACOSX_DEPLOYMENT_TARGET};
if (!defined $v || $v !~ /^\d+\.\d+$/) {
$v = `sw_vers -productVersion`;
if (defined $v && $v =~ /^\s*(\d+\.\d+)/) {
$ENV{MACOSX_DEPLOYMENT_TARGET} = $1;
#warn "MACOSX_DEPLOYMENT_TARGET = $1";
}
}
# 在这里添加
$extra_opts .= " CFLAGS='-fno-stack-check'";
}
3.编译
cd openresty-1.15.8.2
./configure \
--with-cc-opt="-I/usr/local/opt/openssl/include/ -I/usr/local/opt/pcre/include/" \
--with-ld-opt="-L/usr/local/opt/openssl/lib/ -L/usr/local/opt/pcre/lib/" \
-j8
gmake
sudo gmake install
4.增加环境变量
export PATH=/usr/local/openresty/bin:$PATH
export PATH=/usr/local/openresty/nginx/sbin:$PATH
使用
HelloWorld
我们来测试下 OpenResty 是否安装成功,正常情况以下语句应该输出hello, world
resty -e 'print("hello, world")'
准备工作路径
mkdir ~/work
cd ~/work
mkdir logs/ conf/
创建 nginx.conf
配置文件
创建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_block {
ngx.say("<p>hello, world</p>")
}
}
}
}
启动服务
# brew 安装使用openresty
openresty -p `pwd`/ -c conf/nginx.conf
# 源码安装使用nginx
nginx -p `pwd`/ -c conf/nginx.conf
# 测试
curl http://localhost:8080/
停止服务
nginx -s stop -p `pwd`