# 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. 安装cloudera manager使用mysql作为元数据库

    1.首次安装好mysql数据库后,会生成一个随机密码,使用如下办法找到: cat /var/log/mysqld.log |grep password 2.首次安装好mysql数据库后,第一次登陆进去 ...

  2. LeetCode高频题目(100)汇总-Java实现

    LeetCode高频题目(100)汇总-Java实现       LeetCode高频题目(100)汇总-Java实现 目录 第01-50题 [Leetcode-easy-1] Two Sum [Le ...

  3. Android 序列化比对

    本文转自:https://www.zybuluo.com/linux1s1s/note/91046 注:部分内容有更改 在Android中使用序列化,无非两种途经: Parcelable 和 Seri ...

  4. 27、理解js的继承机制(转载自阮一峰)

    Javascript继承机制的设计思想   作者: 阮一峰 日期: 2011年6月 5日 我一直很难理解Javascript语言的继承机制. 它没有"子类"和"父类&qu ...

  5. Spring.Net在ASP.NET Mvc里使用的一个小例子

    就贴个小例子,就不注意格式了. 1.下载dll NuGet的下载地址:http://docs.nuget.org/docs/start-here/installing-nuget 在vs的NuGet里 ...

  6. webpack配置别名alias

    在webpack.config.js中,通过设置resolve属性可以配置查找“commonJS/AMD模块”的基路径,也可以设置搜索的模块后缀名,还可以设置别名alias.设置别名可以让后续引用的地 ...

  7. 第十八篇 模块与包--time&random模块&模块导入import(os.path.dirname(os.path.abspath(__file__)))

    模块 在Python中, 一个.py文件就称为一个模块. 使用模块的好处: 1. 最大的好处就是大大提高了代码的可维护性 2. 编写代码不必从零开始.一个模块编写完毕,就可以被其他地方引用.在写其他程 ...

  8. HDFS分布式集群

    一.HDFS伪分布式环境搭建 Hadoop分布式文件系统(HDFS)被设计成适合运行在通用硬件(commodity hardware)上的分布式文件系统.它和现有的分布式文件系统有很多共同点.但同时, ...

  9. python第三天(dictionary应用)转

    1.题目: python实现英文文章中出现单词频率的统计   前言: 这道题在实际应用场景中使用比较广泛,比如统计历年来四六级考试中出现的高频词汇,记得李笑来就利用他的编程技能出版过一本背单词的畅销书 ...

  10. mysql分布式技术

    所有的分布式技术 dobble zokkiper ngix