編譯安裝 Nginx 1.14

編譯安裝所須要的gcc等軟件再也不贅述
1.下載Nginxhtml

wget http://nginx.org/download/nginx-1.14.0.tar.gz

2.解壓nginx

tar xf nginx-1.14.0.tar.gz

3.切換到解壓後的目錄, 進行配置web

cd nginx-1.14.0

# 添加Nginx組
groupadd nginx    

# 添加Nginx用戶
useradd nginx -g nginx -s /sbin/nologin -M

./configure --user=nginx \    # 設置用戶名
            --group=nginx \   # 設置用戶組
            --prefix=/usr/local/nginx  \ # 設置安裝位置
            --with-http_stub_status_module \  # 用來監控 Nginx 的當前狀態
            --with-http_ssl_module \ # 打開HTTPS功能
            --with-http_realip_module \  # 容許改變客戶端請求頭中X-Real-IP 或 X-Forwarded-For等, 可用於記錄客戶IP
            --with-http_gzip_static_module

4.編譯安裝bash

make && make install
  1. 開機啓動和製做啓停工具

將下面的文件, 寫到/etc/init.d/nginx中工具

#!/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

6.添加執行權限this

chmod 755 /etc/init.d/nginx

7.開機自啓動rest

chkconfig --level 345 nginx on

參考文章: https://www.cnblogs.com/lucky...code

相關文章
相關標籤/搜索