编译安装Nginx软件
[root@db software]#groupadd -r Nginx
[root@db software]# useradd -r -g NginxNginx -s /sbin/nologin
2)创建目录
[root@db ~]# mkdir -pv/var/tmp/Nginx/client
mkdir: created directory `/var/tmp/Nginx'
mkdir: created directory`/var/tmp/Nginx/client'
3、编译安装Nginx
[root@db software]# tar xfNginx-1.8.1.tar.gz
[root@db software]# cd Nginx-1.8.1
[root@db Nginx-1.8.1]# ./configure--prefix=/usr/local/Nginx --conf-path=/etc/Nginx/Nginx.conf--error-log-path=/var/log/Nginx/error.log--http-log-path=/var/log/Nginx/access.log --pid-path=/var/run/Nginx/Nginx.pid--lock-path=/var/lock/Nginx.lock --user=Nginx --group=Nginx--with-http_ssl_module --with-http_flv_module --with-http_stub_status_module--with-http_gzip_static_module--http-client-body-temp-path=/var/tmp/Nginx/client/--http-proxy-temp-path=/var/tmp/Nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/Nginx/fcgi/--http-uwsgi-temp-path=/var/tmp/Nginx/uwsgi--http-scgi-temp-path=/var/tmp/Nginx/scgi --with-pcre
[root@db Nginx-1.8.1]# make &&make install
4、编写Nginx启动脚本
vim/etc/rc.d/init.d/Nginx
#!/bin/sh
#
#Nginx-thisscriptstartsandstopstheNginxdaemon
#
#chkconfig:-8515
#description:NginxisanHTTP(S)server,HTTP(S)reverse\
#proxyandIMAP/POP3proxyserver
#processname:Nginx
#config:/etc/sysconfig/Nginx
#pidfile:/var/run/Nginx.pid
#Sourcefunctionlibrary.
./etc/rc.d/init.d/functions
#Sourcenetworkingconfiguration.
./etc/sysconfig/network
#Checkthatnetworkingisup.
["$NETWORKING"="no"]&&exit0
Nginx="/usr/local/Nginx/sbin/Nginx"
prog=$(basename$Nginx)
Nginx_CONF_FILE="/etc/Nginx/Nginx.conf"
[-f/etc/sysconfig/Nginx]&&./etc/sysconfig/Nginx
lockfile=/var/lock/subsys/Nginx
make_dirs(){
#makerequireddirectories
user=`Nginx-V2>&1|grep"configurearguments:"|sed's/[^*]*--user=\([^]*\).*/\1/g'-`
options=`$Nginx-V2>&1|grep'configurearguments:'`
foroptin$options;do
if[`echo$opt|grep'.*-temp-path'`];then
value=`echo$opt|cut-d"="-f2`
if[!-d"$value"];then
#echo"creating"$value
mkdir-p$value&&chown-R$user$value
fi
fi
done
}
start(){
[-x$Nginx]||exit5
[-f$Nginx_CONF_FILE]||exit6
make_dirs
echo-n$"Starting$prog:"
daemon$Nginx-c$Nginx_CONF_FILE
retval=$?
echo
[$retval-eq0]&&touch$lockfile
return$retval
}
stop(){
echo-n$"Stopping$prog:"
killproc$prog-QUIT
retval=$?
echo
[$retval-eq0]&&rm-f$lockfile
return$retval
}
restart(){
configtest||return$?
stop
sleep1
start
}
reload(){
configtest||return$?
echo-n$"Reloading$prog:"
killproc$Nginx-HUP
RETVAL=$?
echo
}
force_reload(){
restart
}
configtest(){
}
rh_status(){
status$prog
}
rh_status_q(){
rh_status>/dev/null2>&1
}
case"$1"in
start)
rh_status_q&&exit0
$1
;;
stop)
rh_status_q||exit0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q||exit7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q||exit0
;;
*)
echo$"Usage:$0{start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit2
esac
5、设置Nginx开机启动并启动服务
[root@db ~]# chmod +x/etc/init.d/Nginx
[root@db ~]# chkconfig --add Nginx
[root@db ~]# chkconfig Nginx on
[root@db ~]# service Nginx start
原文链接:https://www.f2er.com/centos/381124.html