Nginx源码安装启动及启动脚本
Yum安装环境 yum -y install pcre-devel zlib-devel openssl openssl-devel gcc gcc-c++
关闭防火墙及selinux/ : [root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
导入nginx源码包:nginx-1.16.1.tar.gz
解压:tar zxf nginx-1.16.1.tar.gz
进入到nginx-1.16.1目录下:cd nginx-1.16.1
[root@localhost nginx-1.16.1]# ./configure
[root@localhost nginx-1.16.1]# make && make install
启动nginx:[root@localhost nginx-1.16.1]# /usr/local/nginx/sbin/nginx
页面测试:
启动脚本:
在/etc/init.d目录下创建脚本vi nginx
#!/bin/bash
case $1 in
#停止运行的nginx
'stop'|'STOP')
/usr/local/nginx/sbin/nginx -s stop
;;
#启动nginx
'start'|'START')
/usr/local/nginx/sbin/nginx
;;
#重新启动nginx
'restart'|'RESTART')
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx
;;
#重新加载nginx
'reload'|'RELOAD')
/usr/local/nginx/nginx -s reload
;;
*)
echo 'Usage:service nginx stop|restart|start|reload'
esac
~
给予权限:
[root@localhost init.d]# chmod +x /etc/init.d/nginx
使用脚本启动nginx:
Service nginx start