一、yum源安装
http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
nginx.repo上传到/etc/yum.repos.d目录
yum install nginx -y
验证:nginx -v
/bin/systemctl start nginx.service
报PID file /var/run/nginx.pid not readable (yet?) after start
但启动成功
解决办法:
/usr/lib/systemd/system/nginx.service
[service]PIDFile下一行增加 ExecStartPost=/bin/sleep 0.1
/bin/systemctl daemon-reload
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target[Service]
Type=forking
PIDFile=/var/run/nginx.pid
在这里
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID[Install] WantedBy=multi-user.target
/bin/systemctl restart nginx.service
参考:https://www.cnblogs.com/songxingzhu/p/8568432.html
二、源码
下载页面:http://nginx.org/en/download.html 稳定版tar.gz
其他版本:http://nginx.org/download/
升级nginx,为了避免重新部署应用或重新配置的麻烦,最合适的做法是重新编译一个nginx二进制文件,替换旧的nginx二进制文件,然后重启nginx。
与服务器相一致的环境(这里的环境主要指操作系统大版本,插件版本,文件目录)
configure–make–make install,得到sbin/nginx脚本(备份)
nginx -V 得到编译参数(可能没有)
./configure --prefix=
make 在nginx目录下
cp nginx nginx-old-copy 备份替换
nginx -v 查看版本
nginx -s stop
nginx -t nginx.conf 测试配置文件
nginx -c nginx.conf 选择配置文件启动
nginx: error while loading shared libraries: libpcre.so.1:
cannot open shared object file: No such file or directory
在Redhat 64位服务器上,nginx可能读取的pcre文件为/lib64/libpcre.so.1文件,去查看下
解决办法:
增加软链接 ln -s /usr/local/lib/libpcre.so.1 /lib64
主要参考:
https://blog.csdn.net/atongmu2017/article/details/87974699
https://blog.csdn.net/weixin_34342578/article/details/85969841
编译参数:
openssl:https://www.openssl.org/source/
pcre:https://ftp.pcre.org/pub/pcre/
zlib:https://sourceforge.net/projects/libpng/files/zlib/