Openresty源码编译安装
小于 1 分钟约 226 字
Openresty源码编译安装
安装依赖软件包
yum install -y readline-devel pcre-devel openssl-devel gcc curl
创建服务用户nginx
groupadd -r nginx
useradd -r -g nginx nginx
下载软件包
cd /usr/local/src/
# wget -O openresty-1.15.8.3.tar.gz http://mirrors.lead.cn/source/openresty/openresty-1.15.8.3.tar.gz
wget -O openresty-1.15.8.3.tar.gz http://download-soft.lead.cn/source/openresty/openresty-1.15.8.3.tar.gz
解压安装软件包
tar xf openresty-1.15.8.3.tar.gz
cd openresty-1.15.8.3
./configure --prefix=/usr/local/openresty-1.15.8.3 \
--with-luajit --with-http_iconv_module --user=nginx --group=nginx \
--with-http_realip_module --with-http_sub_module --with-http_flv_module \
--with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module \
--with-http_stub_status_module --with-pcre
gmake && gmake install
软链接
ln -s /usr/local/openresty-1.15.8.3 /usr/local/openresty
ln -s /usr/local/openresty/nginx /usr/local/nginx
# 创建虚拟主机配置目录
mkdir -pv /usr/local/nginx/vhosts
Openresty服务自启动配置
cat > /usr/lib/systemd/system/nginx.service <<EOF
[Service]
Type=forking
PIDFile=/usr/local/openresty/nginx/logs/nginx.pid
ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t
ExecStart=/usr/local/openresty/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
systemctl enable nginx.service
systemctl daemon-reload
systemctl start nginx.service
为Nginx日志添加日志滚动配置
cat > /etc/logrotate.d/nginx <<EOF
/usr/local/nginx/logs/*.log {
create 0664 nginx root
daily
rotate 10
missingok
notifempty
compress
sharedscripts
postrotate
/bin/kill -USR1 `cat /usr/local/nginx/logs/nginx.pid 2>/dev/null` 2>/dev/null || true
endscript
}
EOF