歡迎您光臨本站 註冊首頁

Linux 添加Nginx 到 service 啟動 (完整篇)

←手機掃碼閱讀     火星人 @ 2014-03-08 , reply:0


nginx wiki 中文站:http://wiki.nginx.org/Chs

添加用戶和組

        groupadd www
        useradd -g www -M www

1.安裝nginx所需的pcre庫

    tar zxvf pcre-7.8.tar.gz
    cd pcre-7.8/
    ./configure
    make && make install
    cd ../

Empire CMS,phome.net

2、安裝Nginx

    tar zxvf nginx-1.0.4.tar.gz
    cd nginx-1.0.4/
    ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
    make && make install
    cd ../

vim /etc/init.d/nginx 將下面的代碼複製進去保存!

小插曲VI 小技巧

vi一般用法
一般模式 編輯模式 指令模式
h 左 a,i,r,o,A,I,R,O :w 保存
j 下 進入編輯模式 :w! 強制保存
k 上 dd 刪除游標當前行 :q! 不保存離開
l 右 ndd 刪除n行 :wq! 保存后離開
0 移動到行首 yy 複製當前行 :e! 還原原始檔
$ 移動到行尾 nyy 複製n行 :w filename 另存為
H 屏幕最上 p,P 粘貼 :set nu 設置行號
M 屏幕中央 u 撤消 :set nonu 取消行號


L 屏幕最下 [Ctrl] r 重做上一個動作 ZZ 保存離開
G 檔案一行 [ctrl] z 暫停退出 :set nohlsearch 永久地關閉高亮顯示
/work 向下搜索 :sp 同時打開兩個文檔
?work 向上搜索 [Ctrl] w 兩個文檔設換
gg 移動到檔案第一行 :nohlsearch 暫時關閉高亮顯示

    #!/bin/bash
    # nginx Startup script for the Nginx HTTP Server
    #
    # chkconfig: - 85 15
    # description: Nginx is a high-performance web and proxy server.
    # It has a lot of features, but it's not for everyone.
    # processname: nginx
    # pidfile: /var/run/nginx.pid
    # config: /usr/local/nginx/conf/nginx.conf
    nginxd=/usr/local/nginx/sbin/nginx
    nginx_config=/usr/local/nginx/conf/nginx.conf
    nginx_pid=/usr/local/nginx/nginx.pid
    RETVAL=0
    prog="nginx"

    # Source function library.
    . /etc/rc.d/init.d/functions
    # Source networking configuration.
    . /etc/sysconfig/network
    # Check that networking is up.
    [ ${NETWORKING} = "no" ] && exit 0
    [ -x $nginxd ] || exit 0
    # Start nginx daemons functions.
    start() {
    if [ -e $nginx_pid ];then
    echo "nginx already running...."
    exit 1
    fi
    echo -n $"Starting $prog: "
    daemon $nginxd -c ${nginx_config}
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
    return $RETVAL
    }
    # Stop nginx daemons functions.
    stop() {
    echo -n $    

    "Stopping $prog: "
    killproc $nginxd
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
    }
    # reload nginx service functions.
    reload() {
    echo -n $"Reloading $prog: "
    $nginxd -s reload
    #if your nginx version is below 0.8, please use this command: "kill -HUP `cat ${nginx_pid}`"
    RETVAL=$?
    echo
    }
    # See how we were called.
    case "$1" in
    start)
    start
    ;;
    stop)
    stop
    ;;
    reload)
    reload
    ;;
    restart)
    stop
    start
    ;;
    status)
    status $prog

    RETVAL=$?
    ;;
    *)
    echo $"Usage: $prog {start|stop|restart|reload|status|help}"
    exit 1
    esac
    exit $RETVAL

保持文件后

[root@localhost /]# cd /etc/rc.d/init.d

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

[root@localhost init.d]# /sbin/chkconfig --level 345 nginx on

任何位置都能運行

service nginx start 可選 start | stop | restart | reload | status | help




[火星人 ] Linux 添加Nginx 到 service 啟動 (完整篇)已經有471次圍觀

http://coctec.com/docs/linux/show-post-45769.html