源码安装为1.14版本
nginx下载地址:
http://nginx.org/download/nginx-1.14.0.tar.gz
安装过程:
wget http://nginx.org/download/nginx-1.14.0.tar.gz
tar zxf nginx-1.14.0.tar.gz
cd nginx-1.14.0(进入目录后在里面执行./configure --prefix=/usr/local/nginx)
make && make install
源码的位置在nginx-1.14/src/core(有特殊需求可以去改这些模块)
启动Nginx方式:
usr/local/nginx/sbin/nginx (启动)
pkill nginx (杀死nginx进程,停止nginx服务)或者killall nginx(没有这个命令可以安装psmisc)
查看命令所需安装包:rpm -qf `which killall`
usr/local/nginx/sbin/nginx -t (检测配置文件语法)
usr/local/nginx/sbin/nginx -s reload (重新加载配置文件)
以上启动方式比较麻烦,可以使用服务管理脚本
vim /etc/init.d/nginx
#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start()
{
echo -n $"Starting $prog: "
mkdir -p /dev/shm/nginx_temp
daemon $NGINX_SBIN -c $NGINX_CONF
RETVAL=$?
echo
return $RETVAL
}
stop()
{
echo -n $"Stopping $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=$?
echo
return $RETVAL
}
reload()
{
echo -n $"Reloading $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}
restart()
{
stop
start
}
configtest()
{
$NGINX_SBIN -c $NGINX_CONF -t
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|configtest}"
RETVAL=1
esac
exit $RETVAL
/etc/init.d/nginx start /restart/stop
将服务加入系统开机:
chkconfig --add nginx
chkconfig nginx on