Nginx
一.部署:
1.部署环境:
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
中并给予执行权限
Cp nginx /etc/init.d
Chmod 755 /etc/init.d/nginx
六.开机自启:
Chkconfig --add /ect/init.d/nginx
二.配置:
1. 目录结构:
cd /usr/local/nginx/
ls
A.重要目录:
Html 用来存放网站项目目录的文件夹
Logs 日志文件夹
以 _temp结尾的都是相对应的临时文件夹
B.重要的文件:
Mime.types 定义文件格式的配置文件
Nginx Nginx的二进制文件
Nginx.conf Nginx配置文件
Nginx.pid 运行起来后会产生此文件存放pid
以 .default结尾 相应配置文件的模版文件
2. 配置文件基本结构:
#全局配置项
....
...
...
#网站项目配置项
http{
#网站项目全局配置项
....
....
#每个项目配置项
Server {
...
....
}
Server {
...
...
}
}
3. 配置项:
worker_processes worker进程数,根据
cpu
核心数,一般为4或8
error_log 错误日志存放位置
Pid Nginx运行起来后pid文件存放位置
worker_connections最大连接数一般稍微小于操作系统最大打开句柄数(可设为65535)
include mime.types 使用mine定义的文件格式
log_format 日志格式
Sendfile 文件传输
gzip on gzip压缩
Listen 监听端口
server_name主机名,域名
Root 网站根目录,相对与Nginx 启动文件的目录
Index 主页文件
keepalive_timeout保持链接,超过此时间断开用户链接
作者:lwenxu
链接:https://www.jianshu.com/p/36b38642cf84