# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
// core 和 events 是核心模块
user nginx; // 模块 core 语法 user user [group]
// 指定 nginx worker 进程运行用户/组
worker_processes auto; // 模块 core 语法 worker_processes number
// 启动 worker 进程数量. 1. 利用 SMP 2. 降低worker进程被IO阻塞时的延迟
error_log /var/log/nginx/error.log; // 模块 core 语法 error_log file [ debug | info | notice | warn | error | crit ]
// 错误日志路径
pid /run/nginx.pid; // 模块 core
// 进程id存储文件
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf; // 模块 core 语法 include file | *
// 包含配置文件
// events 块 工作模式与连接数上限
events {
worker_connections 1024; // 模块 events Syntax: worker_connections number
// 单个进程最大连接数
// 支持的最大并发连接 max_clients = worker_connections * worker_processes
// 作为反向代理时的最大并发 max_clients = worker_processes * worker_connections/4 (浏览器默认打开 2 个连接)
}
// http 块
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' // 模块 httplog 语法 log_format name format [format ...] 作用域 http server
'$status $body_bytes_sent "$http_referer" ' // 定义日志格式
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main; // 模块 httplog 语法: access_log path [format [buffer=size | off ] 作用域: http, server, location
// 定义日志路径, 格式
sendfile on; // 模块 httpcore syntax: sendfile [ on|off ] context: http, server, location
// 是否调用系统函数 sendfile() 发送文件
tcp_nopush on; // 模块 httpcore syntax: tcp_nopush [on|off] context: http, server, location
// 启用/禁用 socket 选项 linux 仅 sendfile on 可用
tcp_nodelay on; // 启用/禁用 socket 选项
keepalive_timeout 65; // 模块 httpcore syntax: keepalive_timeout [ time ] context: http, server, location
// 长连接超时时间,单位是秒
// 这个值会用于 header Keep-Alive: timeout=time
// 浏览对于header Keep-Alive: timeout=time 处理
// MSIE and Opera ignore the "Keep-Alive: timeout=<N>" header.
// MSIE keeps the connection alive for about 60-65 seconds, then sends a TCP RST.
// Opera keeps the connection alive for a long time.
// Mozilla keeps the connection alive for N plus about 1-10 seconds.
// Konqueror keeps the connection alive for about N seconds.
types_hash_max_size 2048; // 模块 httpcore Syntax: types_hash_max_size size; Context: http, server, location
// Sets the maximum size of the types hash tables
// # types_hash_max_size 影响散列表的冲突率。types_hash_max_size越大,就会消耗更多的内存,但散列key的冲突率会降低,检索速度就更快。types_hash_max_size越小,消耗的内存就越小,但散列key的冲突率可能上升。
include /etc/nginx/mime.types; // 加载 mime 文件后缀映射文件
default_type application/octet-stream; // 模块 httpcore context: http, server, location
// 默认 MIME type
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf; // 加载模块配置文件
// server 块
server {
listen 80 default_server; // 模块 httpcore syntax: listen address:port [ default [ backlog=num | rcvbuf=size | sndbuf=size | accept_filter=filter | deferred | bind | ssl ] ] context: server
// http 服务器监听地址和端口
listen [::]:80 default_server;
server_name _; // 模块 httpcore syntax: server_name name [... ] context: server
// 参数的作用两个:
// _ 匹配任意域名
// "" 匹配Host 字段为空的请求
// 1. 实现虚拟主机的功能: Nginx 将 server_name 和请求中host字段进行匹配, 成功就响应请求。 匹配顺序
// 1.1 full, static names
// 1.2 names with a wildcard at the start of the name — *.example.com
// 1.3 names with a wildcard at the end of the name — www.example.*
// 1.4 names with regular expressions
// 1.5 如果以上都不匹配, 匹配 listen 指令, 且 listen 指令使用 default 参数, 或隐含使用default 参数 listen 80;
// 2. 见 server_name_in_redirect 指令
root /usr/share/nginx/html; // 模块 httpcore syntax: root path context: http, server, location, if in location
// 主目录
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
// location 匹配块
// ~ #波浪线表示执行一个正则匹配,区分大小写
// ~* #表示执行一个正则匹配,不区分大小写
// ^~ #^~表示普通字符匹配,如果该选项匹配,只匹配该选项,不匹配别的选项,一般用来匹配目录
// = #进行普通字符精确匹配
// @ #"@" 定义一个命名的 location,使用在内部定向时,例如 error_page, try_files
// location 生效优先级
// =前缀的指令严格匹配这个查询。如果找到,停止搜索。
// 所有剩下的常规字符串,最长的匹配。如果这个匹配使用^〜前缀,搜索停止。
// 正则表达式,在配置文件中定义的顺序。
// 如果第3条规则产生匹配的话,结果被使用。否则,如同从第2条规则被使用。
location / {
}
error_page 404 /404.html; // 模块 httpcore syntax: error_page code [ code... ] [ = | =answer-code ] uri | @named_location context: http, server, location, if in location
// 定义 404 错误的响应页面
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# // httpssl 模块指令
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}

Nginx 默认配置解析的更多相关文章

  1. Nginx默认配置语法

    Nginx默认配置语法 1. 我们进入  /etc/nginx/目录下,打开  nginx.conf文件 2. 我们来解析下 这里面标签和各模块的作用 # 设置nginx服务的系统使用用户 user ...

  2. nginx 默认配置语法和日志的format

    nginx 默认配置 查看有nginx哪些默认配置文件,打开/etc/nginx/nginx.conf文件,查看尾行部分 会默认将/etc/nginx/conf.d/文件下其他以.conf结尾的配置文 ...

  3. NGINX(四)配置解析

    前言 nginx配置解析是在初始化ngx_cycle_t数据结构时,首先解析core模块,然后core模块依次解析自己的子模块. 配置解析过程 nginx调用ngx_conf_parse函数进行配置文 ...

  4. nginx常用配置解析

    1.常用公共参数(一般放在http下面,虽然很多参数都支持server和location) keepalive_timeout  60;  #单位为s keepalive_request 2;  #设 ...

  5. nginx.conf 配置解析之 events配置

    worker_connections 1024; 定义每个work_process同时开启的最大连接数,即允许最多只能有这么多连接. accept_mutex on; 当某一个时刻只有一个网络连接请求 ...

  6. nginx.conf 配置解析之文件结构

    nginx.conf配置文件结构如下: ...... #主要定义nginx的全局配置 events{ #events(事件)块:主要配置网络连接相关 } http{ #http块:代理缓存和日志定义绝 ...

  7. nginx默认配置和默认站点启动

    1.nginx的配置文件nginx.conf cd /etc/nginx/ vim nginx.conf 打开后的文件为: user nginx;worker_processes 1; error_l ...

  8. nginx.conf 配置解析之 server配置

    server{} 包含在http{}内部,每一个server{}都是一个虚拟主机(站点) 以下为nginx.conf配置文件中server{  }部分的内容. server { listen ; // ...

  9. nginx.conf 配置解析之 http配置

    官方文档 http://nginx.org/en/docs/参考链接: https://segmentfault.com/a/1190000012672431参考链接: https://segment ...

随机推荐

  1. 学习SQLite基本语句

    SQLite 是一个开源的嵌入式关系数据库,实现自包容.零配置.支持事务的SQL数据库引擎. 其特点是高度便携.使用方便.结构紧凑.高效.可靠. 与其他数据库管理系统不同,SQLite 的安装和运行非 ...

  2. iOS下原生与JS交互(总结)

    iOS开发免不了要与UIWebView打交道,然后就要涉及到JS与原生OC交互,今天总结一下JS与原生OC交互的两种方式. JS调用原生OC篇(我自己用的方式二,简单方便) 方式一 第一种方式是用JS ...

  3. Mysql性能优化四:分库,分区,分表,你们如何做?

    分库分区分表概念 分区 就是把一张表的数据分成N个区块,在逻辑上看最终只是一张表,但底层是由N个物理区块组成的 分表 就是把一张数据量很大的表按一定的规则分解成N个具有独立存储空间的实体表.系统读写时 ...

  4. 机器视觉必知-GenICam相机通用接口标准

    机器视觉必知-GenICam相机通用接口标准 GenICam(相机通用接口): 一种通用软件接口 通用相机接口标准 目前机器视觉行业所使用的相机几乎均以相同方式来进行配置,即:---通过在注册表中的读 ...

  5. 软件工程项目组Z.XML会议记录 2013/10/22

    软件工程项目组Z.XML会议记录 [例会时间]2013年10月22日星期二21:00-22:30 [例会形式]小组讨论 [例会地点]三号公寓楼会客厅 [例会主持]李孟 [会议记录]周敏轩 会议整体流程 ...

  6. Liz问题账户分析系统

    1.理解liz工作情况,了解liz的问题,具有同理心.设想软件应该达成的目标,解决哪些业务. 第一步:就是从系统角度来理解软件,确定对所开发系统的综合要求,并提出这些需求的实现条件,以及需求应该达到的 ...

  7. ios UI自动化测试学习笔记

    一.一些注意事项: 1.做自动化测试时注意如果是真机话首先要设置不锁屏. 2.自动化测试过程中如果程序后台或崩溃了.脚本运行将会暂停,直到程序再次回到前台. 3.必须明确指定关闭自动测试,测试完成或中 ...

  8. weak_ptr打破环状引用

    转自:http://blog.csdn.net/malong777/article/details/48974559 weak_ptr是一种不控制对象生存周期的智能指针,它指向一个shared_ptr ...

  9. A - 移动的骑士

    A - 移动的骑士 Time Limit: 1000/1000MS (C++/Others) Memory Limit: 65536/65536KB (C++/Others) Problem Desc ...

  10. 【Linux】——搭建redis

    1.准备安装文件 redis-3.0.5.tar.gz redis-desktop-manager(可视化管理工具) 2.解压.编译 软件存放目录:/usr/local/software 解压存放路径 ...