nginx配置文件的基本参数略解
Nginx相关地址
源码:https://trac.nginx.org/nginx/browser
官网:http://www.nginx.org/
默认的 nginx 配置文件 nginx.conf 内容如下
nginx.conf
中的注释符号为: #
#user nobody;
worker_processes 1;#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;#pid logs/nginx.pid;events {worker_connections 1024;
}http {include mime.types;default_type application/octet-stream;#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;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;#gzip on;server {listen 80;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location / {root html;index index.html index.htm;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {# listen 8000;# listen somename:8080;# server_name somename alias another.alias;# location / {# root html;# index index.html index.htm;# }#}# HTTPS server##server {# listen 443 ssl;# server_name localhost;# ssl_certificate cert.pem;# ssl_certificate_key cert.key;# ssl_session_cache shared:SSL:1m;# ssl_session_timeout 5m;# ssl_ciphers HIGH:!aNULL:!MD5;# ssl_prefer_server_ciphers on;# location / {# root html;# index index.html index.htm;# }#}}
nginx
文件大致的结构
... #全局块events { #events块...
}http #http块
{... #http全局块server #server块{ ... #server全局块location [PATTERN] #location块{...}location [PATTERN] {...}}server{...}... #http全局块
}
- 全局块:配置影响nginx全局的指令。一般有运行nginx服务器的用户组,nginx进程pid存放路径,日志存放路径,配置文件引入,允许生成worker
process数等。 - events块:配置影响nginx服务器或与用户的网络连接。有每个进程的最大连接数,选取哪种事件驱动模型处理连接请求,是否允许同时接受多个网路连接,开启多个网络连接序列化等。
- http块:可以嵌套多个server,配置代理,缓存,日志定义等绝大多数功能和第三方模块的配置。如文件引入,mime-type定义,日志自定义,是否使用sendfile传输文件,连接超时时间,单连接请求数等。
- server块:配置虚拟主机的相关参数,一个http中可以有多个server。
- location块:配置请求的路由,以及各种页面的处理情况。
上述配置的解释
########### 每个指令必须有分号结束。#################
#user administrator administrators; #配置用户或者组,默认为nobody nobody。
#worker_processes 2; #允许生成的进程数,默认为1
#pid /nginx/pid/nginx.pid; #指定nginx进程运行文件存放地址
error_log log/error.log debug; #制定日志路径,级别。这个设置可以放入全局块,http块,server块,级别以此为:debug|info|notice|warn|error|crit|alert|emerg
events {accept_mutex on; #设置网路连接序列化,防止惊群现象发生,默认为onmulti_accept on; #设置一个进程是否同时接受多个网络连接,默认为off#use epoll; #事件驱动模型,select|poll|kqueue|epoll|resig|/dev/poll|eventportworker_connections 1024; #最大连接数,默认为512
}
http {include mime.types; #文件扩展名与文件类型映射表default_type application/octet-stream; #默认文件类型,默认为text/plain#access_log off; #取消服务日志 log_format myFormat '$remote_addr–$remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for'; #自定义格式access_log log/access.log myFormat; #combined为日志格式的默认值sendfile on; #允许sendfile方式传输文件,默认为off,可以在http块,server块,location块。sendfile_max_chunk 100k; #每个进程每次调用传输数量不能大于设定的值,默认为0,即不设上限。keepalive_timeout 65; #连接超时时间,默认为75s,可以在http,server,location块。upstream mysvr { server 127.0.0.1:7878;server 192.168.10.121:3333 backup; #热备}error_page 404 https://www.baidu.com; #错误页server {keepalive_requests 120; #单连接请求上限次数。listen 4545; #监听端口server_name 127.0.0.1; #监听地址 location ~*^.+$ { #请求的url过滤,正则匹配,~为区分大小写,~*为不区分大小写。#root path; #根目录#index vv.txt; #设置默认页proxy_pass http://mysvr; #请求转向mysvr 定义的服务器列表deny 127.0.0.1; #拒绝的ipallow 172.18.5.54; #允许的ip } }
}
上面是nginx的基本配置
几个常见配置项:
$remote_addr
与$http_x_forwarded_for
用以记录客户端的ip地址;$remote_user
:用来记录客户端用户名称;$time_local
: 用来记录访问时间与时区;$request
: 用来记录请求的url与http协议;$status
: 用来记录请求状态;成功是200;$body_bytes_s ent
:记录发送给客户端文件主体内容大小;$http_referer
:用来记录从那个页面链接访问过来的;$http_user_agent
:记录客户端浏览器的相关信息;
惊群现象
:一个网路连接到来,多个睡眠的进程被同时叫醒,但只有一个进程能获得链接,这样会影响系统性能。
每个指令必须有分号结束。
配置全转发demo
upstream edi {server 127.0.0.1:30018;server 127.0.0.1:30019;server 127.0.0.1:30020;check interval=3000 rise=2 fall=5 timeout=3000 type=http;
# check_keepalive_requests 100;check_http_send "HEAD / HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n";check_http_expect_alive http_2xx http_3xx;}server {listen 8099;server_name localhost;client_max_body_size 30m;location / {proxy_pass http://edi;proxy_set_header Host $host:30020;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}}
nginx配置文件的基本参数略解相关推荐
- nginx下gzip配置参数详解
这篇文章主要介绍了nginx下gzip配置参数详解,本文同时给出了配置例子,以及一些注意事项,需要的朋友可以参考下 Nginx自带的有gzip模块 http://wiki.nginx.org/Ngin ...
- nginx配置文件及工作原理详解
nginx配置文件及工作原理详解 1 nginx配置文件的结构 2 nginx工作原理 1 nginx配置文件的结构 1)以下是nginx配置文件默认的主要内容: #user nobody; #配置用 ...
- Redis配置文件redis.conf参数详解
redis.conf配置文件参数详解 # Redis configuration file example.########################################## GEN ...
- nginx rewrite 配置说明与参数详解
[导读] rewrite是一个静态规则了,下面我来给nginx用户详细介绍rewrite配置与参数详解,有需要了解的同学可进入参考参考.本日志内容来自互联网和平日使用经验,整理一下方便日后参考.正则表 ...
- nginx rewrite php参数,Nginx rewrite伪静态配置参数详解
nginx rewrite 伪静态配置参数和使用例子(附正则使用说明) 正则表达式匹配,其中: * ~ 为区分大小写匹配 * ~* 为不区分大小写匹配 * !~和!~*分别为区分大小写不匹配及不区分大 ...
- mysql参数配置详情_MySQL配置文件mysql.ini参数详解、MySQL性能优化
类型:数据库类大小:1.7M语言:英文 评分:6.6 标签: 立即下载 my.ini(Linux系统下是my.cnf),当mysql服务器启动时它会读取这个文件,设置相关的运行环境参数. my.ini ...
- MySQL配置文件mysql.ini参数详解
my.ini(Linux系统下是my.cnf),当mysql服务器启动时它会读取这个文件,设置相关的运行环境参数. my.ini分为两块:Client Section和Server Section. ...
- mysql.ini环境配置_MySQL配置文件mysql.ini参数详解
my.ini(Linux系统下是my.cnf),当mysql服务器启动时它会读取这个文件,设置相关的运行环境参数. my.ini分为两块:Client Section和Server Section. ...
- mysql ini配置文件分组排序_MySQL配置文件mysql.ini参数详解
[mysqld] port=3306 # mysql服务端默认监听(listen on)的TCP/IP端口 basedir="C:/Program Files/MySQL/MySQL Ser ...
最新文章
- 【细无巨细,包你学会】自学Python运行时会遇到的异常与解决方法
- ETL工具大全,你了解多少
- 什么是 SAP UI5 的 Hybrid Web Containers
- 信联获批个人征信牌照,对普通人有什么重大影响?
- numpy的通用函数:快速的元素级数组函数
- Linux tcpdump
- jQuery学习-显示与隐藏
- 没有找到dllregisterserver输入点_「Mac实用技巧」将浏览器的点密码转换成文本密码的三种方法分享...
- G.Power教程 | 样本量估计
- NAGA-Ⅱ与QPSO算法求解下层为非合作博弈模型的双层规划组合优化模型(铁路开行方案)
- 论文复现——CE-FPN: Enhancing Channel Information for Object Detection
- [SDOI 2015] 星际战争
- zabbix_agentd.exe [13816]: ERROR: cannot connect to Service Manager: [0x00000005]
- WPF之路——绘制几何图形
- MIT又出新玩法,利用AI可轻松分离视频中的乐器声音
- 黑苹果oc清除nvram_基于OpenCore0.6.1的黑苹果安装,小白也能看
- r语言 c长度,如何在R中设置C堆栈的大小?
- 小米推出的付费去MIUI广告服务或扼杀其复苏势头
- 微信公众号如何发布文章到多个自媒体平台?
- 标题Ant Design of Vue 组件库中Modal“确认“按钮和“取消“按钮成英文状态
热门文章
- Packet Tracer学习小结(基本SwitchPort VLan)
- 一行代码教你撩妹手到擒来❤html+css+js烟花告白3D相册(含音乐+可自定义文字)520表白/七夕情人节/求婚
- Unity学习 — 官方中文版本教程详解
- 竞赛题-6283. 正整数和负整数的最大计数
- 使用iMX53 IPU SISG功能控制摄像头闪光灯
- 大二Web课程设计——动漫海贼王(可以很好的应付老师的作业)
- Markdown 中 LaTex 数学公式命令
- Forest - 轻量级HTTP客户端框架
- 安全编程: 开发安全的程序
- PHP是单线程还是多线程?