下载源码:
wget https://openresty.org/download/openresty-1.19.9.1.tar.gz
解压:
tar -xzvf openresty-1.19.9.1.tar.gz
cd openresty-1.19.9.1
准备编译环境
yum install pcre-devel openssl-devel gcc curl
设置安装目录,默认是/usr/local/openresty
./configure --prefix=/data/app/openresty
编译安装
gmake && gmake install
配置环境变量
vim /etc/profile 在末尾添加
export OPENRESTY_PATH=/data/app/openresty
export LUAJIT_PATH=/data/app/openresty/luajit
export NGINX_PATH=/data/app/openresty/nginx
export PATH=$PATH:$LUAJIT_PATH/bin:$OPENRESTY_PATH/bin:$NGINX_PATH/sbin
执行生效命令 source /etc/profile
验证
执行命令: nginx -v 或者 openresty -v 看到输出版本信息: nginx version: openresty/1.19.9.1
开启自启动
vim /usr/lib/systemd/system/nginx.service
[Service]
Type=forking
PIDFile=/data/app/openresty/nginx/logs/nginx.pid
ExecStartPre=/data/app/openresty/nginx/sbin/nginx -t
ExecStart=/data/app/openresty/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl daemon-reload systemctl enable nginx.service
启动openresty
systemctl start nginx.service 停止服务器 systemctl stop nginx.service 重启 systemctl restart nginx.service
验证是否启动启动成功
ps -ef | grep nginx 看到类似下面这种表示已经成功
root 2629 1 0 15:00 ? 00:00:00 nginx: master process /data/app/openresty/nginx/sbin/nginx
nobody 2630 2629 0 15:00 ? 00:00:00 nginx: worker process
|