一.编译安装Nginx服务
- 关闭防火墙,将安装Apache所需软件包传到/opt目录下
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
nginx-1.12.0.tar.gz
- 安装依赖包
yum -y install pcre-devel zlib-devel gcc gcc-c++ make
- 创建运行用户、组(Nginx 服务程序默认以 nobody 身份运行,建议为其创建专门的用户账号,以便更准确地控制其访问权限)
useradd -M -s /sbin/nologin nginx
- 编译安装Nginx
cd /opt
tar zxvf nginx-1.12.0.tar.gz -C /opt/
cd nginx-1.12.0/
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module
make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
- 检查、启动、重启、停止 nginx服务
nginx -t
nginx
cat /usr/local/nginx/logs/nginx.pid
kill -3 <PID号>
kill -s QUIT <PID号>
killall -3 nginx
killall -s QUIT nginx
kill -1 <PID号>
kill -s HUP <PID号>
killall -1 nginx
killall -s HUP nginx
kill -USR1 <PID号>
kill -USR2 <PID号>
- 添加 Nginx 系统服务
方法一:
vim /etc/init.d/nginx
COM="/usr/local/nginx/sbin/nginx"
PID="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$COM
;;
stop)
kill -s QUIT $(cat $PID)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PID)
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit 0
chmod +x /etc/init.d/nginx
chkconfig