添加nginx到系统服务注意事项

1、在/etc/init.d/目录下编写脚本,名为nginx

#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# this script create it by ruijie. at 2014.02.26
# if you find any errors on this scripts,please contact ruijie.
# and send mail to ruijie at gmail dot com.
#            ruijie.qiao@gmail.com


nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid


RETVAL=0
prog="nginx"


[ -x $nginxd ] || exit 0


# Start nginx daemons functions.
start() {
    
    if [ -e $nginx_pid ] && netstat -tunpl | grep nginx &> /dev/null;then
        echo "nginx already running...."
        exit 1
    fi
        
    echo -n $"Starting $prog!"
    $nginxd -c ${nginx_config}
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && touch /var/lock/nginx
    return $RETVAL
}




# Stop nginx daemons functions.
stop() {
    echo -n $"Stopping $prog!"
    $nginxd -s stop
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f /var/lock/nginx
}




# reload nginx service functions.
reload() {


    echo -n $"Reloading $prog!"
    #kill -HUP `cat ${nginx_pid}`
    $nginxd -s reload
    RETVAL=$?
    echo


}


# See how we were called.
case "$1" in
start)
        start
        ;;


stop)
        stop
        ;;


reload)
        reload
        ;;


restart)
        stop
        start
        ;;


*)
        echo $"Usage: $prog {start|stop|restart|reload|help}"
        exit 1
esac


exit $RETVAL

 [root@example ~]# cp nginx /etc/init.d/
[root@example ~]# chmod 755 /etc/init.d/nginx
[root@example ~]# chkconfig --add nginx

3、nginx启动、停止、无间断服务重启

[root@example ~]# service nginx start

[root@example ~]# service nginx stop

[root@example ~]# service nginx reload

添加完以后使用上述命令如果提示No such file or directory 那么可能是因为文件格式不是unix,需要使用命令转化文件格式如下:

 

两个命令的用法相同,不同的是两个命令使用的环境不一样.

dos2unix在CentOS系列的系统中使用,fromdos则在Ubuntu系列的系统中使用。

用法:dos2unix filename = fromdos filename(经测试dos2unix ubuntu也可以用)

意思是:转换文件格式,将windos系统的文件转换成linux系统可以使用的文件格式,否则文件在linux系统中可能会出现错误,如:文件中显示^m 这样的错误字符。

导致这样的错误出现的原因是,windos环境中的换行符是\r\n,而linux系统中的换行符直接\n就行了。

CENTOS下yum install dos2unix -y

UBUNTU下apt-get install tofrodos ?

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值