# 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 Server 16.04 LTS下安装VMware Tools

    1.开启ubuntu server虚拟机 2.vmware workstation菜单项,选取虚拟机(M) --> 安装VMware Tools 3.mkdir /mnt/cdrom  #创建一 ...

  2. python linecache读取过程

    最近使用Python编写日志处理脚本时,对Python的几种读取文件的方式进行了实验.其中,linecache的行为引起了我的注意. Python按行读取文件的经典方式有以下几种: with open ...

  3. 高德API+.NET解决租房问题(可能是最可靠房源:上海互助租房)

    作者:李国宝链接:https://zhuanlan.zhihu.com/p/22113421来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. PS:最近点赞和关注的小伙伴 ...

  4. 解决上传app store卡在正在通过iTunes Store鉴定

    打开终端输入代码即可 cd ~ mv .itmstransporter/ .old_itmstransporter/ "/Applications/Xcode.app/Contents/Ap ...

  5. 用链表实现nodejs的内存对象管理

    虽然javascript拥有垃圾收集,但是垃圾收集机制并不会自动释放持久对象,比如websocks连接. 为了能够在某些特定情况下中止一些连接(比如内存不足),显然要建立全局的对象管理器进行管理. 显 ...

  6. linux学习总结----对象

    内置对象: Date new Date() --->系统当前时间 var d=new Date() d.getFullYear() getMonth() getDay() getDate() g ...

  7. 3.爬虫 urlib库讲解 总结

    urllib库的总结: 用ProcessOn(安利这个软件,够用了)根据前面的几节内容做了个思维导图. urllib库一共有四个模块: request:它是最基本的模块,可以用来模拟发送请求 erro ...

  8. Linux 简单socket实现UDP通信

    服务器端 #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sy ...

  9. Week1 Team Homework #1 from Z.XML-项目选择思路--基于对曾经大作业项目的思考

    这两天试玩了一下去年学长的满分工程<shield star>游戏,再结合了一下他们团队的博客记录,有一种非常牛逼的感觉.具体对于这款游戏的一些思考和看法,毛大神已经说的很好了.因此,这里主 ...

  10. kali linux下的常用bash命令

    虚拟机版本默认用户root 密码toor ls:显示当前目录包含的文件及文件夹 ls -l:以常规格式显示当前目录包含的文件及文件夹(开头字母解释:d:目录 -:文件 c:设备文件 l:链接 b:块设 ...