一、下载
地址:
http://nginx.org/en/download.html
二、安装
1、安装gcc环境
yum install gcc-c++
2、安装pcre库,用于校验正则表达式
#yum -y install pcre pcre-devel
yum -y install pcre*
3、zlib压缩和解压的依赖
#yum -y install zlib zlib-devel
yum -y install zlib*
4、SSL(Https必备)
#yum -y install openssl openssl-devel
yum -y install openssl*
5、解压
tar -zxvf nginx-*
注:解压后得到的是源码,需要编译后才能安装
6、在Nginx目录输入如下命令进行配置,目的是为了创建Makefile文件
#执行命令
#prefix= 指向安装目录(编译安装)
#conf-path= 指向配置文件(nginx.conf)
#error-log-path= 指向错误日志目录
#pid-path= 指向pid文件(nginx.pid)
#http-log-path= 设定access log路径
#with-http_gzip_static_module 启用ngx_http_gzip_static_module支持(在线实时压缩输出数据流)
#with-http_stub_status_module 启用ngx_http_stub_status_module支持(获取nginx自上次启动以来的工作状态)
#with-http_ssl_module 启用ngx_http_ssl_module支持(使支持https请求,需已安装openssl)
./configure \
--prefix=/usr/local/tool/nginx-1.22.0 \
--conf-path=/usr/local/tool/nginx-1.22.0/nginx.conf \
--error-log-path=/usr/local/tool/nginx-1.22.0/logs/error.log \
--pid-path=/usr/local/tool/nginx-1.22.0/logs/nginx.pid \
--http-log-path=/usr/local/tool/nginx-1.22.0/logs/access.log \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_ssl_module
7、make编译
make
8、安装
make install
9、进入sbin目录启动Nginx
#启动
./nginx
#关闭
./nginx -s stop
#重新加载
./nginx -s reload
注:
(1)、在云服务器安装,需要开启默认的防火墙80
(2)、在虚拟机需要关闭防火墙
(3)本地需要关闭防火墙
三、进程模型
master进程:主进程
worker进程:工作进程
worker进程
修改nginx.conf中worker_processes为2
1、检查配置文件是否有问题
./nginx -t
这样代表正常
2、重新加载
./nginx -s reload
现在就出现了两个worker
四、配置结构
1、user nobody;
指定用户,默认是nobody,如果需要一些文件的使用权限的话,可以指定用户。
2、worker_processes
工作进程的数量
3、error_log
error_log logs/error.log notice;
日志的路径以及级别
级别:debug 、info、 notice、warn、error、crit
注:在安装时已经指定了日志路径:-- error-log-path
4、pid
主要存放Nginx的进程号
注:在安装时已经指定了路径:--pid-path
5、events 事件相关配置
操作模式:
默认是epoll(liunx)
use epoll
连接数配置(默认是1024)
worker_connections 10240
6、http