1.安装nginx所需依赖包
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
2.下载并解压nginx安装包
//创建一个文件夹cd /usr/local//下载tar包
tar -xvf nginx-1.13.7.tar.gz
3.安装nginx
cd /usr/local/nginx-1.13.7./configuremakemake install
4.配置nginx.conf即可
5.启动nginx
/usr/local/nginx/sbin/nginx -s reload
6.配置nginx加入service
vi /etc/init.d/nginx
加入以下内容保存,注意修改nginx配置目录
nginx启动脚本
#!/bin/bash
#Startup script for the nginx Web Server
#chkconfig: 2345 85 15
nginx=/usr/local/nginx/sbin/nginx
conf=/usr/local/nginx/conf/nginx.conf
case $1 in
start)
echo -n “Starting Nginx”
$nginx -c $conf
echo ” done.”
;;
stop)
echo -n “Stopping Nginx”
killall -9 nginx
echo ” done.”
;;
test)
$nginx -t -c $conf
echo “Success.”
;;
reload)
echo -n “Reloading Nginx”
ps auxww | grep nginx | grep master | awk ‘{print $2}’ | xargs kill -HUP
echo ” done.”
;;
restart)
$nginx -s reload
echo “reload done.”
;;
*)
echo “Usage: $0 {start|restart|reload|stop|test|show}”
;;
esac
#Startup script for the nginx Web Server
#chkconfig: 2345 85 15
nginx=/usr/local/nginx/sbin/nginx
conf=/usr/local/nginx/conf/nginx.conf
case $1 in
start)
echo -n “Starting Nginx”
$nginx -c $conf
echo ” done.”
;;
stop)
echo -n “Stopping Nginx”
killall -9 nginx
echo ” done.”
;;
test)
$nginx -t -c $conf
echo “Success.”
;;
reload)
echo -n “Reloading Nginx”
ps auxww | grep nginx | grep master | awk ‘{print $2}’ | xargs kill -HUP
echo ” done.”
;;
restart)
$nginx -s reload
echo “reload done.”
;;
*)
echo “Usage: $0 {start|restart|reload|stop|test|show}”
;;
esac
chmod a+x /etc/init.d/nginx
/etc/init.d/nginx start
/etc/init.d/nginx stop
如果想使用service或者systemctl启动,需要执行以下命令:
chkconfig --add /etc/init.d/nginx
ok。
systemctl start nginx 启动systemctl status nginx 查看运行状态systemctl stop nginx 停止
nginx常用操作
# /usr/local/nginx/sbin/nginx -t
# /usr/local/nginx/sbin/nginx -s reload
方式一:传统方法
一、启动
cd usr/local/nginx/sbin
./nginx
二、重启
更改配置重启nginx
kill -HUP 主进程号或进程号文件路径
或者使用
cd /usr/local/nginx/sbin
./nginx -s reload
判断配置文件是否正确
nginx -t -c /usr/local/nginx/conf/nginx.conf
或者
cd /usr/local/nginx/sbin
./nginx -t
三、关闭
查询nginx主进程号
ps -ef | grep nginx
从容停止 kill -QUIT 主进程号
快速停止 kill -TERM 主进程号
强制停止 kill -9 nginx
若nginx.conf配置了pid文件路径,如果没有,则在logs目录下
kill -信号类型 ‘/usr/local/nginx/logs/nginx.pid’
» 订阅本站:https://www.kgraph.cn
» 转载请注明来源:九五青年博客 » 《nginx快速安装文档-并配置成service启动》