gcc pcre-devel zlib-devel openssl openssl-devel
yum list installed | grep "gcc"
yum list installed | grep "pcre-devel"
yum list installed | grep "zlib-devel"
yum list installed | grep "openssl"
yum list installed | grep "openssl-devel"
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
解压文件
tar -zxvf nginx-1.19.6.tar.gz -C /usr/local/
默认:
./configure --prefix=/usr/local/nginx --with-http_ssl_module
全量:
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-stream --with-stream_ssl_module
make
make install
进入nginx 文件 验证安装
./sbin/nginx -t
配置nginx 开机启动
方式一:
vim /etc/rc.d/rc.local
#开机启动nginx
/usr/local/nginx/sbin/nginx
配置启动 重启 停止命令
先关闭nginx
查看nginx 是否启动
配置启动命令
vi /etc/init.d/nginx
#!/bin/bash
# chkconfig: 2345 85 15
# description: nginx Startup script for the Nginx HTTP Server
# processname: nginx
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
授权
chmod +x /etc/init.d/nginx
/sbin/chkconfig nginx on
检查一下
/sbin/chkconfig --list nginx
service nginx start
service nginx stop
service nginx restart
service nginx reload
service nginx status
/etc/init.d/nginx start
/etc/init.d/nginx stop
/etc/init.d/nginx restart
/etc/init.d/nginx reload
/etc/init.d/nginx status
如命令失效
引用
https://blog.csdn.net/weixin_44916431/article/details/109088857
将/etc/init.d/nginx(对应你的nginx service配置文件) 的pidfile 注释去掉,修改内容为logs/nginx.pid
或者
将你nginx主配置文件nginx.conf的pid注释去掉并修改内容为你的nginx service配置文件的pidfile
总之两者pid路径一直即可解决。