nginx手动编译安装
1安装环境包
yum -y install gcc gcc-c++ pcre pcre-devel zlib-devel
上传nginx压缩包到/opt目录下
2 解压nginx压缩包
[root@localhost opt]# tar -zxvf nginx-1.12.2.tar.gz
3 创建运行用户
[root@localhost opt]# useradd -M -s /sbin/nologin nginx
4 编译安装
[root@localhost opt]# mkdir LNMP
[root@localhost nginx-1.12.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
[root@localhost opt]# make && makeinstall
5优化路径
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin
6检查配置文件 /usr/local/nginx/conf/nginx.conf
[root@localhost sbin]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost sbin]# nginx
[root@localhost sbin]# netstat -napt |grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 70403/nginx: master
7 编译安装启动脚本
cd /etc/init.d/
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
$o start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit 0
8 验证编译脚本格式
nginx -t
9 添加启动脚本
chkconfig --add nginx
10检查service 命令能否正常启动关闭
[root@localhost init.d]# netstat -napt |grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 71485/nginx: master
[root@localhost init.d]# service nginx stop
env: /etc/init.d/nginx: 权限不够
[root@localhost init.d]# chmod +x nginx
[root@localhost init.d]# service nginx stop
[root@localhost init.d]# netstat -napt |grep 80
[root@localhost init.d]# service nginx start
[root@localhost init.d]# netstat -napt |grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 71705/nginx: maste