15 09 2019

1.安装依赖包

//一键安装上面四个依赖
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

2.下载并解压安装包

//下载tar包
cd /usr/local
wget http://nginx.org/download/nginx-1.17.3.tar.gz
tar -xvf nginx-1.17.3.tar.gz
//重命名
mv nginx-1.17.3 nginx

3.安装nginx

//进入nginx目录
cd /usr/local/nginx
//执行命令
./configure
//执行make命令
make
//执行make install命令
make install

4.配置nginx.conf

//打开配置文件
vi /usr/local/nginx/conf/nginx.conf

mac我这边直接使用FinalShell工具,地址:http://www.hostbuf.com/c/131.html,可以直接打开文件编辑,详细配置后面再细说。

5.启动nginx

//进入nginx/sbin目录
cd /usr/local/nginx/sbin
//启动
./nginx  -c  /usr/local/nginx/conf/nginx.conf

查看nginx进程是否启动:

ps -ef | grep nginx

6.访问服务器ip查看


出现该界面说明成功

7.常用命令

//进入nginx/sbin目录
cd /usr/local/nginx/sbin
//启动
./nginx
//关闭
./nginx -s stop
//重启
./nginx -s reload

7.设置为系统服务,随系统启动而启动

//创建启动文件
vi /etc/init.d/nginx

编辑文件(i)

#! /bin/sh
# chkconfig: - 85 15
# description: nginx is a World Wide Web server. It is used to serve

PATH=/usr/local/servers/nginx/sbin

DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/servers/nginx/sbin/$NAME
CONFIGFILE=/usr/local/servers/nginx/conf/$NAME.conf
PIDFILE=/usr/local/servers/nginx/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

set -e
[ -x "$DAEMON" ] || exit 0

do_start() {
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}

do_stop() {
$DAEMON -s stop || echo -n "nginx not running"
}

do_reload() {
$DAEMON -s reload || echo -n "nginx can't reload"
}

case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
;;
reload|graceful)
echo -n "Reloading $DESC configuration..."
do_reload
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
do_stop
do_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac

exit 0

保存退出(esc&:wq)

//设置系统启动
vi /etc/rc.d/rc.local

在最后一行添加

/etc/init.d/nginx start

随后重启服务器,nginx随系统启动而启动

延伸阅读
  1. Windows下IIS搭建Ftp服务器
  2. Nginx开启Gzip压缩提升页面加载速度
  3. Nginx安装及配置(linux)
  4. Docker(6):Dockerfile文件指令详解
  5. Docker(10):Docker-Compose简介及安装
发表评论