nginx 1.21.3 编绎安装 最新版 ubuntu

  1. 卸载
#删除nginx,–purge包括配置文件
sudo apt-get --purge remove nginx
#自动移除全部不使用的软件包
sudo apt-get autoremove
#罗列出与nginx相关的软件
dpkg --get-selections|grep nginx
#删除查询出与nginx有关的软件
sudo apt-get --purge remove nginx-common
#查看nginx正在运行的进程,如果有就kill掉
ps -ef |grep nginx
#kill nginx进程
sudo kill  -9  7875 7876 7877 7879
#全局查找与nginx相关的文件
sudo  find  /  -name  nginx*
#依依删除列出的所有文件
sudo rm -rf file
  1. 安装nginx 依赖
#安装nginx 依赖
sudo apt-get install libpcre3 libpcre3-dev
#编绎安装最新版openssl
##下载openssl
wget https://www.openssl.org/source/openssl-1.1.1l.tar.gz --no-check-certificate
##清除openssl软件包和软件的配置文件
apt purge openssl
##解压并进入openssl解压目录
tar -xvf openssl-1.1.1l.tar.gz
cd openssl-1.1.1l
##安装openssl
./config shared --prefix=/usr/local/ssl
make
make install
##配置openssl
ln -s /usr/local/ssl/lib/libssl.so.1.1 /usr/lib/libssl.so.1.1
ln -s /usr/local/ssl/lib/libcrypto.so.1.1 /usr/lib/libcrypto.so.1.1
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl /usr/include/openssl.bak
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/ssl/include/openssl /usr/include/openssl
echo "/usr/local/ssl/lib" >> /etc/ld.so.conf
#查看版本信息,确定是否安装成功
ldconfig -v
openssl  version
  1. 下载最新版nginx
#返回目录
cd ..
#下载
wget http://nginx.org/download/nginx-1.21.3.tar.gz
#解压
tar -xvf nginx-1.21.3.tar.gz
  1. 安装 nginx
#进入解压目录
cd nginx-1.21.3
#安装,不写 --prefix 默认安装路径也是 /usr/local/nginx
./configure --prefix=/usr/local/nginx/
make
make install
#配置
cp -f objs/nginx  /usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx –t
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
/usr/local/nginx/sbin/nginx -s reload
/usr/local/nginx/sbin/nginx -V
ps -ef | grep nginx
  1. 添加自启动
#新 nginx 启动内容,内容如下
vim /etc/init.d/nginx

#/etc/init.d/nginx 内容
#! /bin/sh
# chkconfig: 2345 55 25
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# run 'update-rc.d -f nginx defaults', or use the appropriate command on your
# distro. For CentOS/Redhat run: 'chkconfig --add nginx'

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

# Author:   licess
# website:  http://lnmp.org

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=nginx
#/etc/nginx 为自己的安装目录
NGINX_BIN=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/etc/local/nginx/logs/$NAME.pid

case "$1" in
    start)
        echo -n "Starting $NAME... "

        if netstat -tnpl | grep -q nginx;then
            echo "$NAME (pid `pidof $NAME`) already running."
            exit 1
        fi

        $NGINX_BIN -c $CONFIGFILE

        if [ "$?" != 0 ] ; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
        ;;

    stop)
        echo -n "Stoping $NAME... "

        if ! netstat -tnpl | grep -q nginx; then
            echo "$NAME is not running."
            exit 1
        fi

        $NGINX_BIN -s stop

        if [ "$?" != 0 ] ; then
            echo " failed. Use force-quit"
            exit 1
        else
            echo " done"
        fi
        ;;

    status)
        if netstat -tnpl | grep -q nginx; then
            PID=`pidof nginx`
            echo "$NAME (pid $PID) is running..."
        else
            echo "$NAME is stopped"
            exit 0
        fi
        ;;

    force-quit)
        echo -n "Terminating $NAME... "

        if ! netstat -tnpl | grep -q nginx; then
            echo "$NAME is not running."
            exit 1
        fi

        kill `pidof $NAME`

        if [ "$?" != 0 ] ; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
        ;;

    restart)
        $0 stop
        sleep 1
        $0 start
        ;;

    reload)
        echo -n "Reload service $NAME... "

        if netstat -tnpl | grep -q nginx; then
            $NGINX_BIN -s reload
            echo " done"
        else
            echo "$NAME is not running, can't reload."
            exit 1
        fi
        ;;

    configtest)
        echo -n "Test $NAME configure files... "

        $NGINX_BIN -t
        ;;

    *)
        echo "Usage: $0 {start|stop|force-quit|restart|reload|status|configtest}"
        exit 1
        ;;

esac

#1.开机自启设置
#安装sysv-rc-conf
apt install sysv-rc-conf
chmod +x /etc/init.d/nginx
sysv-rc-conf nginx
sysv-rc-conf nginx on
sysv-rc-conf -list nginx
#如果1.开机自启设置 无效,采用以下方案
vi /etc/rc.local
#添加内容
/etc/init.d/nginx start
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值