文章目录
一、安装Nginx
1、安装语言包
[root@localhost ~]# yum -y install pcre-devel zlib-devel gcc gcc-c++
[root@localhost ~]# useradd -M -s /sbin/nologin nginx
[root@localhost ~]# tar zxvf nginx-1.12.2.tar.gz -C /opt
2、配置编译安装
[root@localhost ~]# cd /opt/nginx-1.12.2/
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module //开启stub_ status状态统计模块//
[root@localhost ~]# make && make install
[root@localhost ~]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ //让系统识别命令
3、检查、启动、重启、停止
[root@localhost ~]# nginx- t //检查
[root@localhost ~]# nginx //启动
[root@localhost ~]# killall -1 nginx //重启
[root@localhost ~]# killall -3 nginx //停止
yum install elinks -y //安装软件
elinks http://localhost //验证访问,会提示welcome语句
4、制作管理角本
[root@localhost ~]# vim /etc/init.d/nginx
#!/bin/bash
#chkconfig: - 99 20
#description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$PROG
;;
stop)
kill -s QUIT $(cat $PIDF)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
*)
echo "Usage: $0 {start |stop|restart |reload}"
exit 1
esac
exit 0
[root@localhost ~]# chmod +x /etc/init.d/nginx
[root@localhost ~]# chkconfig --add nginx
[root@localhost ~]# chkconfig --level 35 nginx on
#访问验证