• linux 安装 nginx,并且注册成一个服务


    * 一键安装四个依赖
    yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

    * 安装 nginx

    $ cd /usr/local/
    $ wget http://nginx.org/download/nginx-1.8.0.tar.gz
    $ tar -zxvf nginx-1.8.0.tar.gz
    $ cd nginx-1.8.0 
    $ ./configure
    $ make && make install

    * 启动 nginx

    /usr/local/nginx/sbin/nginx

    * 查看是否启动:

    ps aux | grep nginx   //能看到 nginx 进程表示启动成功

    或者直接访问:

    curl 127.0.0.1:80

    看到 nginx 欢迎页的 html 代码表示成功

    * nginx 的启动停止重启操作:

    启动:/usr/local/nginx/sbin/nginx
    停止:/usr/local/nginx/sbin/nginx -s stop
    重启:/usr/local/nginx/sbin/nginx -s reload

    * 设置 nginx 开机自启

    vi /etc/rc.local
    底部加:
    /usr/local/nginx/sbin/nginx

    * 把 nginx 配置成一个服务:

    vi /etc/init.d/nginx

    * 服务脚本:

    #!/bin/sh
    #chkconfig: - 85 15
     
    PATH=/usr/local/nginx/sbin
    DESC="nginx daemon"
    NAME=nginx
    DAEMON=/usr/local/nginx/sbin/$NAME
    CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
    PIDFILE=/usr/local/nginx/logs/$NAME.pid
    SCRIPTNAME=/etc/init.d/$NAME
     
    set -e
    [ -x "$DAEMON" ] || exit 0
     
    do_start() {
    $DAEMON -c $CONFIGFILE || echo -n "nginx already running"
    }
     
    do_stop() {
    $DAEMON -s stop || echo -n "nginx not running"
    }
     
    do_reload() {
    $DAEMON -s reload || echo -n "nginx can't reload"
    }
     
    case "$1" in
    start)
    echo -n "Starting $DESC: $NAME"
    do_start
    echo "."
    ;;
    stop)
    echo -n "Stopping $DESC: $NAME"
    do_stop
    echo "."
    ;;
    reload|graceful)
    echo -n "Reloading $DESC configuration..."
    do_reload
    echo "."
    ;;
    restart)
    echo -n "Restarting $DESC: $NAME"
    do_stop
    do_start
    echo "."
    ;;
    *)
    echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
    exit 3
    ;;
    esac
    exit 0

    保存后赋予权限:

    chmod 777 nginx

    添加服务:

    chkconfig --add nginx

    重开一下终端窗口,然后再测试:(有时候要等一会才生效,具体原因不明)

    启动:systemctl start nginx.service
    停止:systemctl stop nginx.service
    重启:systemctl restart nginx.service
  • 相关阅读:
    新的一天,新的一周
    mysql重启失败,报错:starting mysql。 the server quit without updating pid file (/[failed]l/mysql/data/hostname.pid])
    rpm包安装、配置与卸载
    python高效运用(十)———文件(File)、输入输出的基本操作
    paramiko--------远程服务器连接工具
    main
    thread同步测试
    实验二测试
    《信息安全系统设计与实现》学习笔记9
    实验二 OpenSSL API使用
  • 原文地址:https://www.cnblogs.com/xuehuashanghe/p/16303476.html
Copyright © 2020-2023  润新知