Nginx各项配置的含义
#user nobody; #配置用户或者组,默认为nobody nobody
worker_processes 4; #允许生成的进程数,默认为1
worker_cpu_affinity 00000001 00000010 00000100 00001000; #为每个进程分配一个CPU
worker_rlimit_nofile 102400; #为nginx工作进程改变打开最多文件描述符数目的限制。用来在不重启主进程的情况下增加限制。
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #指定日志路径,级别。这个设置可以放入全局块,http块,server块,级别依次为:debug|info|notice|warn|error|crit|alert|emerg
#pid logs/nginx.pid; #指定nginx进程运行文件存放地址
events {
accept_mutex on; #设置网路连接序列化,防止惊群现象发生,默认为on
multi_accept on; #设置一个进程是否同时接受多个网络连接,默认为off
use epoll; #使用epoll(linux2.6的高性能方式)事件驱动模型,select|poll|kqueue|epoll|resig|/dev/poll|eventport
worker_connections 102400; #最大连接数,默认为512
}
http {
include mime.types; #文件扩展名与文件类型映射表
default_type application/octet-stream; #默认文件类型,默认为text/plain
lua_package_path "/usr/local/lib/lua/?.lua;;"; #lua库位置
charset utf-8; #字符集
server_names_hash_bucket_size 128; # 保存服务器名字的hash表
client_header_buffer_size 4k; #用来缓存请求头信息的,容量4K,如果header头信息请求超过了且没有配置client_header_buffer_size,nginx会直接返回400错误
large_client_header_buffers 4 32k; #如果large_buffer还是无法容纳,那么就会返回414(处理request_line)/400(处理request_header)错误
client_max_body_size 300m; #允许客户端请求的最大单文件字节数
tcp_nodelay on; #提高数据的实时响应性
client_body_buffer_size 512k; #缓冲区代理缓冲用户端请求的最大字节数(请求多)
proxy_connect_timeout 5s; #nginx跟后端服务器连接超时时间(代理连接超时)
proxy_read_timeout 60s; #连接成功后,后端服务器响应时间(代理接收超时)
proxy_send_timeout 5s; #后端服务器数据回传时间(代理发送超时)
proxy_buffer_size 16k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小
proxy_buffers 4 64k; #该指令设置缓冲区的大小和数量,从被代理的后端服务器取得的响应内容,会放置到这里
proxy_busy_buffers_size 128k; #所有处在busy状态的buffer size加起来不能超过proxy_busy_buffers_size
proxy_temp_file_write_size 128k; #如果response的内容很大的话,Nginx会接收并把他们写入到temp_file里去。busy的buffer传输完了会从temp_file里面接着读数据,直到传输完毕
gzip on; #NGINX可以压缩静态资源
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2; #压缩级别大小,最小1,最大9,值越小,压缩后比例越小,CPU处理更快; 值越大压缩后占用带宽越少。
gzip_types text/plain application/x-javascript text/css application/xml; #压缩类型:text js css xml 都会被压缩
gzip_vary on; #作用是在http响应中增加一行,目的是改变反向代理服务器的缓存策略
#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;
#access_log off; #取消服务日志
#日志格式
# ip 远程用户 当地时间 请求URL 状态 发送的大小 响应的头 客户端使用的浏览器 页面响应的时间
log_format myFormat '$remote_addr–$remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $request_time $http_x_forwarded_for'; #自定义格式
access_log logs/access.log myFormat; #combined为日志格式的默认值
sendfile on; #允许sendfile方式传输文件,默认为off,可以在http块,server块,location块
#sendfile_max_chunk 100k; #每个进程每次调用传输数量不能大于设定的值,默认为0,即不设上限
#tcp_nopush on;
tcp_nopush on; #防止网络阻塞
#keepalive_timeout 0;
keepalive_timeout 65; #连接超时时间,默认为75s,可以在http,server,location块
#gzip on;
#上游服务器
upstream mysvr {
#负载均衡算法,默认为round-robin轮循
ip_hash; #每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题,ip_hash不支持weight和backup
server 192.168.5.91:7878 max_fails=2 fail_timeout=10s;
server 192.168.5.92:7878 max_fails=2 fail_timeout=10s;
#server 192.168.5.91:7878 max_fails=2 fail_timeout=10s weight=1;
#server 192.168.5.92:7878 max_fails=2 fail_timeout=10s weight=2;
#server 192.168.5.90:7878 backup; #热备
}
#error_page 404 https://www.baidu.com; #错误页
server {
keepalive_requests 120; #单连接请求上限次数
listen 9080; #监听端口
server_name localhost; #监听地址 127.0.0.1
#charset koi8-r;
#access_log logs/host.access.log main;
#location ~*^.+$ { #请求的url过滤,正则匹配,~为区分大小写,~*为不区分大小写。
# #root path; #根目录
# #index vv.txt; #设置默认页
# proxy_pass http://mysvr; #请求转向mysvr 定义的服务器列表
# deny 127.0.0.1; #拒绝的ip
# allow 172.18.5.54; #允许的ip
#}
location /test {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_next_upstream_timeout 10s;
proxy_next_upstream_tries 2;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header upstream_addr $upstream_addr;
proxy_pass http://mysvr;
}
#nginx主页
location / {
root html;
index index.html index.htm;
}
#用lua脚本向reids存值
location /lua/set {
default_type 'text/plain';
content_by_lua_file conf/lua/setKeyValue.lua;
}
#用lua脚本从reids取值
location /lua/get {
default_type 'text/plain';
content_by_lua_file conf/lua/getKey.lua;
}
#静态资源代理
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
root /var/local/static;
expires 30d;
}
#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;
}
}
Nginx各项配置的含义的更多相关文章
- nginx location配置
nginx location配置 location在nginx中起着重要作用,对nginx接收到的请求字符串进行处理,如地址定向.数据缓存.应答控制.代理转发等location语法location ...
- Nginx如何配置Http、Https、WS、WSS?
写在前面 当今互联网领域,Nginx是使用最多的代理服务器之一,很多大厂在自己的业务系统中都是用了Nginx作为代理服务器.所以,我们有必要了解下Nginx对于Http.Https.WS.WSS的各项 ...
- nginx的配置总结
总体而言,nginx的配置比起apache来是要简洁很多,而言容易理解得多的,另外官网的文档也十分的简洁易懂.我们先看一个简化版的配置文件nginx.conf: #user nobody; worke ...
- nginx服务配置---php服务接入
前言: 最近要搭建一个内部的wiki系统, 网上搜了一圈, 也从知乎上搜集了一些大神的评价和推荐. 重点找了几个开源的wiki系统, 不过发现他们都是采用php来实现的. 于是乎需要配置php环境, ...
- Nginx安装配置PHP(FastCGI)环境的教程
这篇是Nginx安装配置PHP(FastCGI)环境的教程.Nginx不支持对外部程序的直接调用或者解析,所有的外部程序(包括PHP)必须通过FastCGI接口来调用. 一.什么是 FastCGI F ...
- nginx 详细配置
Nginx全局变量 Nginx中有很多的全局变量,可以通过$变量名来使用.下面列举一些常用的全局变量: 变量 说明 boxClass 需要执行动画的元素的 变量 说明 $args 请求中的参数,如ww ...
- 写给大忙人的nginx核心配置详解
由于当前很多应该都是前后端分离了,同时大量的基于http的分布式和微服务架构,使得很多时候应用和不同项目组之间的系统相互来回调用,关系复杂.如果使用传统的做法,都在应用中进行各种处理和判断,不仅维护复 ...
- mac 安装nginx,并配置nginx的运行环境
1. 安装nginx // 查询有没有nginx brew search nginx //开始安装nignx brew install nginx 2. 检查nignx是否安装成功 nginx -V ...
- Nginx location 配置用法及正则例子
Nginx location 配置语法 1. location [ = | ~ | ~* | ^~ ] uri { ... } 2. location @name { ... } ...
随机推荐
- WPF中,如何将Vista Aero效果扩展到整个窗口
原文:WPF中,如何将Vista Aero效果扩展到整个窗口 WPF中,如何将Vista Aero效果扩展到整个窗口 ...
- C++学习009预处理器指令符号 # ## #@ 符号的使用
# ## #@ 符号是预处理器指令符号. 当预处理器遇到#指令符号时,会将#之后的部分用双引号括起来 当预处理去遇到##指令符号时,直接将##前后部分连接起来 当预处理器遇到#@指令符号,将#@之后的 ...
- git安装后Gitbase闪退,gui无法使用问题解决
一般是因为null.sys导致,根本原因应该还是你装的盗版系统有问题,解决办法如下 cmd 打开命题提示符后 输入 sc start null 看 null.sys是否有问题,如果有问题,重新 ...
- KVM WEB管理工具——WebVirtMgr(二)日常配置
配置宿主机 1.登录WebVirtMgr管理平台 2.添加宿主机 选择首页的WebVirtMgr -->Addd Connection 选择“SSH链接“,设置Label,IP,用户 注意:La ...
- Leetcode 55. Jump Game & 45. Jump Game II
55. Jump Game Description Given an array of non-negative integers, you are initially positioned at t ...
- Leetcode 678.有效的括号字符串
有效的括号字符串 给定一个只包含三种字符的字符串:( ,) 和 *,写一个函数来检验这个字符串是否为有效字符串.有效字符串具有如下规则: 任何左括号 ( 必须有相应的右括号 ). 任何右括号 ) 必须 ...
- K-Means和FCM聚类
K均值聚类是基于原型的.划分的聚类方法.聚类数K由用户指定,初始的K个聚类中心随机选取,然后将每个点分派到最近的聚类中心,形成K个簇,接下来重新计算每个簇的聚类中心,重复上一步,直到簇不发生变化或达到 ...
- 最短路径——Bellman-Ford算法
一.相关定义 最短路径:求源点到某特定点的最短距离 特点:Bellman-Ford算法主要是针对有负权值的图,来判断该图中是否有负权回路或者存在最短路径的点 局限性:算法效率不高,不如SPFA算法 时 ...
- 【积累】根据CheckBox的不选中 ,用JQuery 清除 RidaoButtonList 的选中项
如题,项目要求无刷新更新数据. 1)Web页面布局 Html以及效果图
- lintcode-93-平衡二叉树
93-平衡二叉树 给定一个二叉树,确定它是高度平衡的.对于这个问题,一棵高度平衡的二叉树的定义是:一棵二叉树中每个节点的两个子树的深度相差不会超过1. 您在真实的面试中是否遇到过这个题? Yes 样例 ...