以下安装方法完全适用于nginx的安装,下面./configure
阶段只需要去掉--with-luajit
参数,安装OpenResty主要为了使用LuaJIT。
安装依赖
因为OpenResty是基于Nginx构建的,安装之前需要先安装Nginx的依赖组件。
CentOS, RHEL,Rocky, and Fedora
1
| sudo yum install gcc make pcre pcre-devel zlib zlib-devel openssl openssl-devel
|
基于Debian的Linux发行版
1
| sudo apt-get install make openssl-devel liblz-dev libpcre3
|
编译安装
下载源码
最新版请到官网确认:https://openresty.org/en/download.html
1
2
3
4
5
6
7
8
| #下载及解压openresty
wget https://openresty.org/download/openresty-1.19.9.1.tar.gz
tar -zxvf openresty-1.19.9.1.tar.gz
#下载及解压njs(非必须,第三方模块我这边选了njs)
wget https://hg.nginx.org/njs/archive/9578cc729205.tar.gz
tar -zxvf 9578cc729205.tar.gz
mv njs-9578cc729205/ njs && mv njs openresty-1.19.9.1/bundle/
|
编译及安装OpenResty及Module。
1
2
3
4
5
6
7
8
9
10
| #生成Makefile
./configure --prefix=/app/openresty \
--with-luajit \
--with-http_ssl_module \
--with-http_auth_request_module \
--add-dynamic-module=./bundle/njs/nginx \
--modules-path=/app/openresty/nginx/modules
#编译及安装
sudo make && make install
|
配置systemd服务
1
| sudo vim /lib/systemd/system/nginx.service
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| [Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/app/openresty/nginx/logs/nginx.pid
ExecStartPre=/app/openresty/nginx/sbin/nginx -t
ExecStart=/app/openresty/nginx/sbin/nginx
ExecReload=/app/openresty/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
|
1
2
3
4
| #配置开机启动
systemctl --now enable nginx
#确认服务状态
systemctl status nginx
|