ubuntu 16.04二进制安装Nginx

一、安装依赖库

安装gcc与g++依赖库:

apt install build-essential

apt install libtool

安装 pcre依赖库:

sudo apt update

sudo apt install libpcre3 libpcre3-dev

安装 zlib依赖库

sudo apt install zlib1g-dev

安装 ssl依赖库

apt install openssl

更新依赖库

apt update

二、下载Nginx

官网地址:http://nginx.org/en/download.html

wget http://nginx.org/download/nginx-1.13.0.tar.gz

三、解压安装Nginx

tar -zxvf nginx-1.13.0.tar.gz

cd nginx-1.13.0

./configure --prefix=/usr/local/nginx-1.13.0

make

sudo make install

四、启动Nginx

sudo /usr/local/nginx-1.13.0/sbin/nginx

./nginx -v  查看版本号
./nginx -s stop  停止nginx
./nginx -s reload  重新加载nginx

五、设置Nginx开机自启

输入vim /etc/init.d/nginx进入编辑页面

#! /bin/sh
#chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# Author: rui ding
# Modified: Geoffrey Grosenbach http://www.linuxidc.com
# Modified: Clement NEDELCU
# Reproduced with express authorization from its contributors
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/wubin/nginx/sbin/$NAME
SCRIPTNAME=/etc/init.d/$NAME


# If the daemon file is not found, terminate the script.
test -x $DAEMON || exit 0

d_start() {
$DAEMON || echo -n " already running"
}

d_stop() {
$DAEMON –s quit || echo -n " not running"
}

d_reload() {
$DAEMON –s reload || echo -n " could not reload"
}

case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
reload)
echo -n "Reloading $DESC configuration..."
d_reload
echo "reloaded."
;;
restart)
echo -n "Restarting $DESC: $NAME"
d_stop
# Sleep for two seconds before starting again, this should give the
# Nginx daemon some time to perform a graceful stop.
sleep 2
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
exit 3
;;
esac
exit 0

编写完成后,输入wq!保存退出

输入chkconfig  nginx  on即可,如图所示

 

posted @ 2022-03-21 15:06  斌斌的博客  阅读(291)  评论(0编辑  收藏  举报