- 卸载
sudo apt-get --purge remove nginx
sudo apt-get autoremove
dpkg --get-selections|grep nginx
sudo apt-get --purge remove nginx-common
ps -ef |grep nginx
sudo kill -9 7875 7876 7877 7879
sudo find / -name nginx*
sudo rm -rf file
- 安装nginx 依赖
sudo apt-get install libpcre3 libpcre3-dev
wget https://www.openssl.org/source/openssl-1.1.1l.tar.gz --no-check-certificate
apt purge openssl
tar -xvf openssl-1.1.1l.tar.gz
cd openssl-1.1.1l
./config shared --prefix=/usr/local/ssl
make
make install
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
- 下载最新版nginx
cd ..
wget http://nginx.org/download/nginx-1.21.3.tar.gz
tar -xvf nginx-1.21.3.tar.gz
- 安装 nginx
cd nginx-1.21.3
./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
- 添加自启动
vim /etc/init.d/nginx
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=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
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
vi /etc/rc.local
/etc/init.d/nginx start