CentOS 6.5將Nginxi添加爲服務

1、正確安裝Nginx
安裝Nginx請自行度娘

2、編寫Nginx啓動腳本並給權限
如下爲一簡單的Nginx啓動腳本,如需更復雜的請自行百度。

#!/bin/bash
#
# chkconfig: -85 15
# description: Nginx is a World Wide Web server
# processname: Nginx

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
    ;;
    reload)
    echo -n "Reloading Nginx"
    ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP
    echo " done"
    ;;
    restart)
    $0 stop
    $0 start
    ;;
    show)
    ps -aux | grep nginx
    ;;
    *)
    echo -n "Usage: $0 {start | restart | reload | test | show}"
    ;;
esac

將文件命名爲nginx,並放到/etc/init.d/
修改nginx的權限
給剛編寫的nginx添加可執行權限

[root@localhost init.d]# chmod +x ./nginx

3、測試

[root@localhost init.d]# service nginx start
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章