A.0.0.3 安装nginx


1.下载nginx 安装包


nginx: download


2.上传文件到服务器



3.检查安装环境

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



变更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路径一直即可解决。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值