nginx編譯安裝

#####軟件:nginx1.10.1nginx

關閉防火牆命令:service iptables stop[stop|start|restart]git

查看環境變量:echo $PATHgithub

  1. 新建nginx用戶
groupadd -g 108 -r www
   useradd -u 108 -g 108 www -s /sbin/nologin
複製代碼
  1. 安裝服務
yum install gcc
   yum install pcre-devel
   yum install openssl-devel
複製代碼
  1. 解壓 編譯 安裝bash

    直播rtmp模塊nginx-rtmp-module :dom

git clone https://github.com/arut/nginx-rtmp-module.git
複製代碼
tar -zxvf nginx-1.10.1.tar.gz
   cd nginx-1.10.1
複製代碼
./configure 
複製代碼

--prefix=/usr/local/nginx
--sbin-path=/usr/sbin/nginx
--conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--pid-path=/var/run/nginx.pid
--lock-path=/var/run/nginx.lock
--http-client-body-temp-path=/var/cache/nginx/client_temp
--http-proxy-temp-path=/var/cache/nginx/proxy_temp
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp
--http-scgi-temp-path=/var/cache/nginx/scgi_temp
--user=www
--group=www
--with-http_ssl_module
--with-http_realip_module
--with-http_addition_module
--with-http_sub_module
--with-http_dav_module
--with-http_flv_module
--with-http_mp4_module
--with-http_gunzip_module
--with-http_gzip_static_module
--with-http_random_index_module
--with-http_secure_link_module
--with-http_stub_status_module
--with-http_auth_request_module
--with-threads
--with-stream
--with-stream_ssl_module
--with-http_slice_module
--with-mail
--with-mail_ssl_module
--with-file-aio
--with-http_v2_module
--with-ipv6
--with-pcre
--add-module=/root/nginx-rtmp-module-masterui

make
   make install
複製代碼
  1. 建立cache目錄
mkdir -p /var/cache/nginx/client_temp
複製代碼
  1. 添加環境變量
export PATH=$PATH:/usr/sbin/nginx
複製代碼
  1. 添加nginx啓用控制腳本
vi /etc/init.d/nginx
複製代碼
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# pidfile: /var/nginx/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/sbin/nginx"

prog=$(basename $nginx)

NGINX_CONF_FILE="/etc/nginx/nginx.conf"

lockfile=/var/run/nginx.lock

start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    configtest || return $?
    stop
    start
}

reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}

force_reload() {
    restart
}

configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}

rh_status() {
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac
複製代碼

腳本添加執行權限this

chmod +x /etc/init.d/nginx
複製代碼
  1. 說明spa

    • 配置文件:/etc/nginx/nginx.conf
    • 啓動控制:/etc/init.d/nginx {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}
  2. 配置自啓動rest

chkconfig --add nginx
chkconfig nginx on
複製代碼
相關文章
相關標籤/搜索