step4:创建nginx启动脚本
#!/bin/bash
# chkconfig: - 18 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/sbin/nginx"
NGINX_CONF="/etc/nginx/nginx.conf"
NGINX_PID="/var/run/nginx.pid"
RETVAL=0
prog="Nginx"
#Source networking configuration
. /etc/sysconfig/network
# Check networking is up
[ ${NETWORKING} = "no" ] && exit 0
[ -x $NGINX_SBIN ] || exit 0
start() {
echo -n $"Starting $prog: "
touch /var/lock/subsys/nginx
daemon $NGINX_SBIN -c $NGINX_CONF
RETVAL=$?
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -TERM
rm -rf /var/lock/subsys/nginx /var/run/nginx.pid
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
设置开机启动
[root@www ~]# chmod 755 /etc/init.d/nginx
[root@www ~]# chkconfig --add nginx
[root@www ~]# chkconfig nginx on
[root@www ~]# service nginx stop
Stopping nginx (via systemctl): [ OK ]
[root@www ~]# service nginx start
Starting nginx (via systemctl): [ OK ]
设置防火墙规则,允许外部访问80端口
[root@www ~]# firewall-cmd --permanent --add-port=80/tcp
[root@www ~]# firewall-cmd --reload
step5:测试访问
在浏览器输入
更多Nginx相关教程见以下内容:
搭建基于Linux6.3+Nginx1.2+PHP5+MySQL5.5的Web服务器全过程
CentOS 6.3下配置Nginx加载ngx_pagespeed模块