一.部署:
1.部署環(huán)境:
CentOS6.3
2.編譯前準備:
安裝編譯工具:yum -y install gcc gcc-c++ automake autoconf libtool make
3.下載源碼包:
cd
mkdir src
cd src
wget [ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre2-10.22.tar.gz](ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/)
wget [http://zlib.net/zlib-1.2.8.tar.gz](http://zlib.net/zlib-1.2.8.tar.gz)
wget [https://www.openssl.org/source/openssl-1.0.1g.tar.gz](https://www.openssl.org/source/openssl-1.0.1g.tar.gz)
wget [http://nginx.org/download/nginx-1.10.1.tar.gz](http://nginx.org/download/nginx-1.10.1.tar.gz)
tar -zxvf nginx-1.10.1.tar.gz
tar -zxvf pcre2-10.22.tar.gz
tar -zxvf zlib-1.2.8.tar.gz
tar -zxvf openssl-1.0.1t.tar.gz
4.編譯安裝:
# install pcre
cd pcre2-8.22/
./configure
make&&make install
# install zlib
cd ..
cd zlib-1.2.8/
./configure
make&&make install
# install openssl
cd ..
cd openssl-1.0.1t/
./configure
make&&make install
# install nginx
cd ..
cd nginx-1.10.1/
./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=/root/src/pcre2-10.22/ --with-zlib=/root/src/zlib-1.2.8/ --with-openssl=/root/src/openssl-1.0.1t/
make&&make install
#Start Nginx
/usr/local/nginx/nginx
五.Nginx啟動腳本:
#/bin/bash
# Author:lwen
# Descript: The shell is to manage the nginx
# chkconfig: 2345 33 34
# description: The Nginx HTTP Server
binpath=/usr/local/nginx/nginx;
pidpath=/usr/local/nginx/nginx.pid
if [ -f ${pidpath} ]; then
pid=`cat $pidpath`
fi
start(){
if [ -f ${pidpath} ]; then
echo "The Nginx is already running !"
else
echo "Starting Nginx ..."
$binpath
fi
}
stop(){
if [ -f ${pidpath} ]; then
echo "Stopping Nginx ..."
$binpath -s stop
else
echo "The Nginx haven't run !"
fi
}
reload() {
$binpath -s reload
}
status() {
if [ -f ${pidpath} ]; then
echo "The Nginx(pid: ${pid} ) is running..."
else
echo "The Nginx is stop!"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
reload)
reload
;;
status)
status
;;
*)
echo "The Usage: /etc/init.d/nginx (start|stop|restart|reload|status)"
;;
esac
將啟動腳本添加到/etc/init.d
中并給予執(zhí)行權(quán)限
Cp ?nginx ?/etc/init.d
Chmod 755 ?/etc/init.d/nginx
六.開機自啟:
Chkconfig --add /ect/init.d/nginx
二.配置:
1. 目錄結(jié)構(gòu):
cd ?/usr/local/nginx/
ls
A.重要目錄:
Html ?用來存放網(wǎng)站項目目錄的文件夾
Logs ?日志文件夾
以 ?_temp結(jié)尾的都是相對應(yīng)的臨時文件夾
B.重要的文件:
Mime.types ??定義文件格式的配置文件
Nginx ???Nginx的二進制文件
Nginx.conf ?Nginx配置文件
Nginx.pid ?運行起來后會產(chǎn)生此文件存放pid
以 .default結(jié)尾 ?相應(yīng)配置文件的模版文件
2. 配置文件基本結(jié)構(gòu):
#全局配置項
....
...
...
#網(wǎng)站項目配置項
http{
#網(wǎng)站項目全局配置項
....
....
#每個項目配置項
Server {
...
....
}
Server {
...
...
}
}
3. 配置項:
worker_processes ?worker進程數(shù)个从,根據(jù)
cpu
核心數(shù),一般為4或8
error_log ?錯誤日志存放位置
Pid ?Nginx運行起來后pid文件存放位置
worker_connections最大連接數(shù)一般稍微小于操作系統(tǒng)最大打開句柄數(shù)(可設(shè)為65535)
include ?mime.types ?使用mine定義的文件格式
log_format ??日志格式
Sendfile ?文件傳輸
gzip ?on ?gzip壓縮
Listen ??監(jiān)聽端口
server_name主機名瞬铸,域名
Root ??網(wǎng)站根目錄推穷,相對與Nginx 啟動文件的目錄
Index ?主頁文件
keepalive_timeout保持鏈接律秃,超過此時間斷開用戶鏈接