nodejs+nginx+mongdb+redis安裝學習筆記(之nginx安裝)

第二步:安裝nginx

這裏使用OpenResty(一個通過擴展 Nginx 實現的高性能Web服務器,使用Nginx+Lua的方式,對於高併發網站開發非常有用)

安裝

(1)進入官方網站http://openresty.org/cn/找到下載地址如https://openresty.org/download/ngx_openresty-1.9.3.1.tar.gz
(2) 在 /opt 目錄下通過wget下載

wget https://openresty.org/download/ngx_openresty-1.9.3.1.tar.gz

(3)解壓

tar xvf  ngx_openresty-1.9.3.1.tar.gz

(4) 移動目錄

mv  ngx_openresty-1.9.3.1 nginxopen

(5) 安裝以下的開發庫

apt-get install libreadline-dev libpcre3-dev libssl-dev perl

(6)進入nginxopen目錄,依次執行以下命令,安裝完成

./configure --prefix=/opt/nginx/
make
make install

設置開機啓動

(1) 安裝服務管理

sudo apt-get install sysv-rc-conf

(2)創建自啓動腳本

  • 在/etc/init.d/目錄下創建nginx

    sudo vi /etc/init.d/nginx

  • 並加入內容

 #!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/opt/nginx/nginx/sbin/$NAME
CONFIGFILE=/opt/nginx/nginx/conf/$NAME.conf
PIDFILE=/opt/nginx/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() {
 kill -INT `cat $PIDFILE` || echo -n "nginx not running"
}

do_reload() {
 kill -HUP `cat $PIDFILE` || 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

(3) 設置開機啓動

sudo sysv-rc-conf nginx  on

手動重啓,停止命令

sudo /etc/init.d/nginx restart
sudo /etc/init.d/nginx stop

*安裝成功後的一些文件存放位置
*nginx path prefix: “/opt/nginx//nginx”
nginx configuration prefix: “/opt/nginx//nginx/conf”
nginx pid file: “/opt/nginx//nginx/logs/nginx.pid”
nginx error log file: “/opt/nginx//nginx/logs/error.log”
nginx http access log file: “/opt/nginx//nginx/logs/access.log”
nginx http client request body temporary files: “client_body_temp”
nginx http fastcgi temporary files: “fastcgi_temp”
nginx http scgi temporary files: “scgi_temp”*

發佈了22 篇原創文章 · 獲贊 18 · 訪問量 32萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章