Nginx是一个非常实用的高性能的HTTP和反向代理做事器,本日
语法: user user [group]
缺省值: nobody nobody
指定Nginx Worker进程运行用户,默认是nobody帐号。

error_log
语法: error_log file [ debug | info | notice | warn | error | crit ]
缺省值: ${prefix}/logs/error.log
指定缺点日志的存放位置和级别。
include
语法: include file |
缺省值: none
include 指令还支持像下面配置一样的全局包含的方法,例如包含一个目录下所有以\"大众.conf\"大众结尾的文件: include vhosts/.conf;
pid
语法: pid file
进程id存储文件。可以利用 kill -HUP cat /var/log/nginx.pid/ 对Nginx进行配置文件重新加载。
worker_processes
语法: worker_processes number
缺省值: 1
指定事情进程数。nginx可以利用多个worker进程(建议与本机CPU核心数同等)。
二: 事宜模块的常用组件worker_connections
语法:worker_connections number
通过worker_connections和worker_proceses可以打算出maxclients: max_clients = worker_processes worker_connections
作为反向代理,max_clients为: max_clients = worker_processes worker_connections/4 ,由于浏览器访问时会通过连接池建立多个连接。
use
语法:use [ kqueue | rtsig | epoll | /dev/poll | select | poll | eventport ]
如果在./configure的时候指定了不止一种事宜模型,
那么可以设置个中一个,以便见告nginx利用哪种事宜模型。默认情形下nginx会在./configure时找出最适宜系统的事宜模型。
事宜模型是指Nginx处理连接的方法。
三: HTTP模块的核心组件和变量紧张有三个浸染域: http,server,location
server
语法:server {...}
浸染域: http
配置一台虚拟机。
location
语法: location [=|~|~|^~] /uri/ { ... }
浸染域: server
配置访问路径的处理方法。
listen
语法: listen address:port [ default [ backlog=num | rcvbuf=size | sndbuf=size | accept_filter=filter | deferred | bind | ssl ]
默认值: listen 80
浸染域: server
指定当前虚拟机的监听端口。
alias
语法: alias file-path|directory-path;
浸染域: location
设置指定location利用的路径.把稳它跟 root 相似,但是不改变文件的根路径,仅仅是利用文件系统路径
root
语法: root path
默认值:root html
浸染域:http, server, location
指定目录的上级目录,并且该上级目录要含有location指定名称的同名目录。
root和alias的差异示例
location /abc/ {
alias /home/html/abc/;
}
#在这段配置下,http://test/abc/a.html就指定的是/home/html/abc/a.html。这段配置亦可改成
location /abc/ {
root /home/html/;
}
#这样,nginx就会去找/home/html/目录下的abc目录了,得到的结果是相同的。
四: 多台做事器配置负载均衡http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream allserver {
#ip_hash;
server 127.0.0.1:8083 down;
server 127.0.0.1:8084 weight=3;
server 127.0.0.1:8001;
server 127.0.0.1:8002 backup;
}
server {
listen 8012;
server_name localhost;
location / {
proxy_pass http://allserver;
}
}
}
ip_hash; nginx中的ip_hash技能能够将某个ip的要求定向到同一台后端,这样一来这个ip下的某个客户端和某个后端就能建立起稳固的session
1.down 表示当前的 server 暂时不参与负载
2.weight 默认为 1.weight 越大,负载的权重就越大。
3.backup: 其它所有的非 backup 机器 down 或者忙的时候,要求 backup机器。以是这台机器压力会最轻。
五: 常见变量$arg_name
要求中的name参数
$args
要求中的参数
$binary_remote_addr
远程地址的二进制表示
$body_bytes_sent
已发送的体字节数
$content_length
HTTP要求信息里的\公众Content-Length\"大众
$content_type
要求信息里的\公众Content-Type\"大众
$document_root
针对当前要求的根路径设置值
$document_uri
与$uri相同; 比如 /test2/test.php
$host
要求信息中的\"大众Host\"大众,如果要求中没有Host行,则即是设置的做事器名
$hostname
机器名利用 gethostname系统调用的值
$http_cookie
cookie 信息
$http_referer
引用地址
$http_user_agent
客户端代理信息
$http_via
末了一个访问做事器的Ip地址。
$http_x_forwarded_for
相称于网络访问路径
$is_args
如果要求行带有参数,返回“?”,否则返回空字符串
$limit_rate
对连接速率的限定
$nginx_version
当前运行的nginx版本号
$pidworker
进程的PID
$query_string
与$args相同
$realpath_root
按root指令或alias指令算出确当前要求的绝对路径。个中的符号链接都会解析成真是文件路径
$remote_addr
客户端IP地址
$remote_port
客户端端口号
$remote_user
客户端用户名,认证用
$request
用户要求
$request_body
这个变量(0.7.58+)包含要求的紧张信息。在利用proxy_pass或fastcgi_pass指令的location中比较故意义
$request_body_file
客户端要求主体信息的临时文件名
$request_completion
如果要求成功,设为\公众OK\公众;如果要求未完成或者不是一系列要求中末了一部分则设为空
$request_filename
当前要求的文件路径名,比如/opt/nginx/www/test.php
$request_method
要求的方法,比如\"大众GET\公众、\"大众POST\公众等
$request_uri
要求的URI,带参数;比如http://localhost:88/test1/
$scheme
所用的协议,比如http或者是https
$server_addr
做事器地址,如果没有用listen指明做事器地址,利用这个变量将发起一次系统调用以取得地址(造成资源摧残浪费蹂躏)
$server_name
要求到达的做事器名
$server_port
要求到达的做事器端口号
$server_protocol
要求的协议版本,“HTTP/1.0\"大众或\"大众HTTP/1.1”
$uri
要求的URI,可能和最初的值有不同,比如经由重定向之类的
user mask; # 利用的用户和组
worker_processes 4; #事情进程数(建议与本机CPU核心数同等)
#error_log logs/error.log;
#error_log logs/error.log notice;
error_log logs/error.log info;
pid logs/nginx.pid;#nginx 进程id存储文件
events {
worker_connections 1024; #每个worker的最大连接数
}
http {
include mime.types; #包含一个文件描述了:不同文件后缀对应的MIME,见案例剖析
default_type application/octet-stream; #制订默认MIME类型为二进制字节流
#log_format main '$remote_addr - $remote_user [$time_local] \"大众$request\"大众 '
# '$status $body_bytes_sent \"大众$http_referer\"大众 '
# '\"大众$http_user_agent\公众 \公众$http_x_forwarded_for\"大众';
# access_log logs/access.log main; #指令 access_log 指派路径、格式和缓存大小。
sendfile on; #开启调用Linux的sendfile(),供应文件传输效率
#tcp_nopush on; #是否许可利用socket的TCP_NOPUSH或TCP_CORK选项
#keepalive_timeout 0;
keepalive_timeout 65; #指定客户端连接为长连接时保持活动的超时时间,在这个韶光之后,做事器会关掉连接。
# gzip on; #设置gzip,压缩文件
# lua_code_cache off;
include conf.d/.conf; #引入其他的配置文件
#配置一台虚拟机
server {
listen 80;
server_name 127.0.0.1;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.htm mis.html index.html ;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}