wss1051 发表于 2018-11-13 10:25:36

Linux 添加Nginx 到 service 启动 (完整篇)

  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 ../
  

  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 屏幕最下          +r 重做上一个动作       ZZ 保存离开
  
G 档案最后一行      +z 暂停退出            :set nohlsearch   永久地关闭高亮显示
  
/work 向下搜索                                 :sp 同时打开两个文档
  
?work 向上搜索                                 +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
  

  保持文件后
  # cd /etc/rc.d/init.d
  #chmod +x nginx
  # /sbin/chkconfig --level 345 nginx on

  任何位置都能运行   service nginx start         可选start | stop | restart |>

页: [1]
查看完整版本: Linux 添加Nginx 到 service 启动 (完整篇)