目录php
Nginx:... 1nginx
NGINX简介和安装... 1web
网站... 1express
全称... 2centos
二次开发版... 2缓存
Nginx的特性... 2性能优化
基本功能... 2服务器
web服务相关的功能... 2架构
Nginx的基本架构:... 3并发
模块类型... 3
nginx主要用途... 3
nginx安装配置... 3
编译安装... 3
前期准备... 3
从官网获取源码包... 4
查看编译帮助文档... 4
安装... 4
启动NGINX. 5
NGINX配置文件... 5
配置文件组成... 5
配置文件配置指令... 6
配置文件结构... 6
全局配置网段:main block. 6
事件驱动配置... 6
http配置段... 6
配置文件简介... 7
main配置段... 7
http://nginx.org/, C10k;
http://www.nginx.com
完整写法engine X:简写为nginx
二次开发版tengine(淘宝), OpenResty
master/worker两级架构,master主控进程,worker为子进程,每一个worker都有本身的 核心模块例如为了实现http功能有ht_core,和非核心模块例如ht_proxy,ht_fastcgi
不停机更新配置文件、更换日志、更新服务器程序版本;
10000个keep-alive链接模式下的非活动链接(保持链接,可是没有数传输)仅消耗2.5M内存;
a) 一个master进程,可生成一个或多个worker进程;
b) master: 加载配置文件、管理worker进程、平滑升级,...
c) worker:http服务,http代理,fastcgi代理,...
a) Standard HTTP modules
b) Optional HTTP modules
c) Mail modules
使用yum info nginx查看相关信息,显示没有匹配的软件包能够列出,说明nginx并无被收录至centos发行光盘中。因此可使用epel源来安装nginx。
yum -y groupinstall "Development Tools" "Server Platform Development"
yum -y install pcre zlib openssl pcre-devel pcre-devel openssl-devel
PCRE – Supports regular expressions. Required by the NGINX Core and Rewrite modules.
zlib – Supports header compression. Required by the NGINX Gzip module.
OpenSSL – Supports the HTTPS protocol. Required by the NGINX SSL module and others.
$ wget https://nginx.org/download/nginx-1.14.2.tar.gz
$ tar zxf nginx-1.14.2.tar.gz #解压
$ cd nginx-1.14.2
./config --help #返回以下图结果
注意有些模块前带有--without,这表明此模块默认加载。有些模块前带有--with这表明此模块默认不被加载须要在编译的时候使用--with-*_module编译。
./configure
--prefix=/usr/local/nginx
--conf-path=/etc/nginx/nginx.conf
--user=nginx
--group=nginx
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--pid-path=/var/run/nginx/nginx.pid
--lock-path=/var/lock/nginx.lock
--with-http_ssl_module
--with-http_stub_status_module
--with-http_gzip_static_module
--with-debug
make &&make install
/usr/local/nginx/sbin/nginx
这个报错是由于我在编译安装时指定运行worker的用户为nginx。然而我没有在系统中建立这个用户。
a) 除去上图全部文件外,nginx配置文件还包括在nginx.conf中使用include指令指定的配置文件。
b) 上图中有相似A.conf和A.conf.default的配置文件。其中A.conf.default,是默认的配置文件
a) 内置变量:由模块引入;
b) 自定义变量:
l set variable value;
c) 引用变量:$variable
event {
...
}
http {
...
server {
...
server_name
root
alias
location /uri/ {
}
...
}
server {
...
}
}
a) user USERNAME [GROUPNAME];
指定用于运行worker进程的用户和组;
eg:user nginx nginx;
b) pid /PATH/TO/PID_FILE;
指定nginx进程的pid文件路径;
eg:pid /var/run/nginx.pid;
c) worker_rlimit_nofile number;
指定一个worker进程所可以打开的最大文件数量;
a) worker_processes auto|number;
worker进程的个数;一般应该为物理CPU核心数量减1;
能够为"auto",实现自动设定;
b) worker_cpu_affinity auto|CPUMASK CPUMASK ...;
设置worker与CPU的亲和力。经过该指令能够将一个worker进程绑定到指定CPU。
c) worker_priority number;
经过nice值,设置worker进程的优先级,从-20(最高)到19(最低),默认为0。 注意内核的有优先级为-5,所以不建议设值<=-5
a) daemon off|on;
是否以守护进程方式启动nignx;
eg :daemon off
b) master_process on|off;
是否以master/worker模型运行nginx,设置为off将不启动worker进程;
c) error_log file [level];
l file:其值能够是以下几种
PATH/TO/LOG:记录日志文件的位置。s
Stderr:将日志到处到标准输出
syslog:server=adderess:将日志发往指定的日志服务器
memory:size:将日志输出到内存中
l level:设定日志级别
debug, info, notice, warn, error, crit, alert, or emerg
注意:错误日志文件及其级别;出于调试的须要,能够设定为debug;但debug仅在编译时使用了“--with-debug”选项时才有效;