# 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. 【转】Ubuntu 14.04下Django+MySQL安装部署全过程

    一.简要步骤.(阿里云Ubuntu14.04) Python安装 Django Mysql的安装与配置 记录一下我的部署过程,也方便一些有需要的童鞋,大神勿喷~ 二.Python的安装 由于博主使用的 ...

  2. 【Consul】Consul架构-Consensus协议

    Consul使用Consensus协议提供一致性(Consistency)--CAP定义的一致性.Consensus协议是基于"Raft:In search of an Understand ...

  3. 转MySQL详解--索引

    写在前面:索引对查询的速度有着至关重要的影响,理解索引也是进行数据库性能调优的起点.考虑如下情况,假设数据库中一个表有10^6条记录,DBMS的页面大小为4K,并存储100条记录.如果没有索引,查询将 ...

  4. C#调用C++编写的dll

    界面还是C#写的方便点,主要是有一个可视化的编辑器,不想画太多的时间在界面上.但是自己又对C++了解的多一些,所以在需要一个良好的界面的情况下,使用C++来写代码逻辑,将其编译成一个dll,然后用C# ...

  5. 安装mathtype出问题卸载后 office2016打开mathtype弹错误窗口

    解决方法:找到 C:\Program Files (x86)\Microsoft Office\root\Office16\STARTUP目录下的MathType Commands 6 For Wor ...

  6. restAssured + TestNG测试接口,以下是一个get 请求。

    package Elaine.Test.G.APITest; import org.testng.Assert;import org.testng.annotations.BeforeTest;imp ...

  7. 学习人工智能的第五个月[字典学习[Dictionary Learning,DL]]

    摘要: 大白话解释字典学习,分享第五个月的学习过程,人生感悟,最后是自问自答. 目录: 1.字典学习(Dictionary Learning,DL) 2.学习过程 3.自问自答 内容: 1.字典学习( ...

  8. static 关键字解析(转)

    static关键字解析   Java中的static关键字解析 static关键字是很多朋友在编写代码和阅读代码时碰到的比较难以理解的一个关键字,也是各大公司的面试官喜欢在面试时问到的知识点之一.下面 ...

  9. wpa_supplicant 初始化

    几个重要的结构体介绍: 1. struct wpa_interface --- Parameters for wpa_supplicant_add_iface(). wpa_interface对应网络 ...

  10. 前台如何处理后台返回的json数据

    后台返回的json数据格式: { "state": true, "data": { "id": 0, "name": & ...