1.版本选择
OpenResty是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。
下载地址http://openresty.org/cn/download.html.
安装环境
centos7.4
2.安装依赖环境
yum -y install make zlib zlib-devel gcc gcc-c++ libtool openssl openssl-devel pcre pcre-devel
3.解压安装包
tar -zxvf openresty-1.17.8.tar.gz
4.修改版本号
cd openresty-1.17.8.1/bundle/nginx-1.17.8/src/core
vi nginx.h
5.进行预编译
cd openresty-1.17.8.1
./configure --prefix=/usr/local/nginx
6.编译
gmake
7.安装
gmake install
8.配置nginx服务
新建/usr/lib/systemd/system/nginx.service文件
#/usr/lib/systemd/system/nginx.service
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/nginx/sbin/nginx -c /usr/local/nginx/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
9.常见命令
systemctl start nginx.service
systemctl stop nginx.service
systemctl restart nginx.service
10.其他
验证nginx配置文件是否正确
进入nginx安装目录sbin下,输入命令./nginx -t
Nginx服务(如果没有配置nginx.service)
进入nginx可执行目录sbin下,
cd /usr/local/nginx/nginx/sbin/
./nginx 启动
./nginx -s stop 停止
./nginx -s reload 重启
11.日志分割
vi /etc/logrotate.d/nginx
/data/nginx_logs/*.log {#/data/nginx_logs/*.log是配置文件里nginx日志所在目录
daily #按日分割日志
rotate 5 #保留最近5天
missingok
notifempty
create 644 root root
nocompress
dateext
sharedscripts
postrotate
[ -e /usr/local/nginx/nginx/logs/nginx.pid ] && kill -USR1 `cat /usr/local/nginx/nginx/logs/nginx.pid`
endscript
}
12.添加编译参数
同版本添加模块,需要重新编译,
例如,openresty默认没有加realip模块,需要加此模块
cd openresty-1.17.8.1
./configure --prefix=/usr/local/nginx --with-http_realip_module
gmake
mv /usr/local/nginx/nginx/sbin/nginx /usr/local/nginx/nginx/sbin/nginx.bak
cp /data/openresty-1.17.8.1/build/nginx-1.17.8.1/objs/nginx /usr/local/nginx/nginx/sbin/
systemctl restart nginx