#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各项配置的含义的更多相关文章

  1. nginx location配置

    nginx location配置   location在nginx中起着重要作用,对nginx接收到的请求字符串进行处理,如地址定向.数据缓存.应答控制.代理转发等location语法location ...

  2. Nginx如何配置Http、Https、WS、WSS?

    写在前面 当今互联网领域,Nginx是使用最多的代理服务器之一,很多大厂在自己的业务系统中都是用了Nginx作为代理服务器.所以,我们有必要了解下Nginx对于Http.Https.WS.WSS的各项 ...

  3. nginx的配置总结

    总体而言,nginx的配置比起apache来是要简洁很多,而言容易理解得多的,另外官网的文档也十分的简洁易懂.我们先看一个简化版的配置文件nginx.conf: #user nobody; worke ...

  4. nginx服务配置---php服务接入

    前言: 最近要搭建一个内部的wiki系统, 网上搜了一圈, 也从知乎上搜集了一些大神的评价和推荐. 重点找了几个开源的wiki系统, 不过发现他们都是采用php来实现的. 于是乎需要配置php环境, ...

  5. Nginx安装配置PHP(FastCGI)环境的教程

    这篇是Nginx安装配置PHP(FastCGI)环境的教程.Nginx不支持对外部程序的直接调用或者解析,所有的外部程序(包括PHP)必须通过FastCGI接口来调用. 一.什么是 FastCGI F ...

  6. nginx 详细配置

    Nginx全局变量 Nginx中有很多的全局变量,可以通过$变量名来使用.下面列举一些常用的全局变量: 变量 说明 boxClass 需要执行动画的元素的 变量 说明 $args 请求中的参数,如ww ...

  7. 写给大忙人的nginx核心配置详解

    由于当前很多应该都是前后端分离了,同时大量的基于http的分布式和微服务架构,使得很多时候应用和不同项目组之间的系统相互来回调用,关系复杂.如果使用传统的做法,都在应用中进行各种处理和判断,不仅维护复 ...

  8. mac 安装nginx,并配置nginx的运行环境

    1. 安装nginx // 查询有没有nginx brew search nginx //开始安装nignx brew install nginx 2. 检查nignx是否安装成功 nginx -V ...

  9. Nginx location 配置用法及正则例子

    Nginx location 配置语法     1. location [ = | ~ | ~* | ^~ ] uri { ... }     2. location @name { ... }   ...

随机推荐

  1. Android面试收集录 2D绘图与动画技术

    1.如何在Android应用程序的窗口上绘制图形? 继承View 实现View中的onDraw()方法 2.如何绘制圆,空心椭圆? canvas.drawArc或canvas.drawCircle方法 ...

  2. struts2官方 中文教程 系列八:异常处理

    在本教程中,我们将探讨如何启用Struts 2框架处理web应用程序生成的任何未捕获的异常.Struts 2提供了健壮的异常处理,包括能够自动记录任何未捕获的异常,并将用户重定向到错误web页面. 贴 ...

  3. P1332 血色先锋队

    P1332 血色先锋队 题目描述 巫妖王的天灾军团终于卷土重来,血色十字军组织了一支先锋军前往诺森德大陆对抗天灾军团,以及一切沾有亡灵气息的生物.孤立于联盟和部落的血色先锋军很快就遭到了天灾军团的重重 ...

  4. android activity状态保存

    一.被其他任务打断(来电话),再次打开希望保留数据 private String SAVE_INSTANCE_TAG = "ATWAL"; @Override protected ...

  5. vi/vim 命令使用详解

    1.Linux下创建文件 vi test.txt 或者 vim test.txt 或者 touch test.txt 2.vi/vim 使用 基本上 vi/vim 共分为三种模式,分别是命令模式(Co ...

  6. Windows下nginx作为静态资源服务器使用

    一.Nginx下载与安装 1.nginx官方下载地址:http://nginx.org/ 2.下载完后将压缩包解压即可 3.nginx配置文件为根目录下conf\nginx.conf 二.Nginx常 ...

  7. Qt HUD(平显)演示程序绿色版

    把一个黑底白字的程序改成黑底绿字 上对比图,左侧是原本,右侧是仿造,有些地方比例还是有问题 其实这个程序没有啥技术含量,就是画 #include "mainwindow.h" #i ...

  8. JavaScript调试中Console命令

    JS调试中,用console.log 感觉比 alert 好用,不用弹出窗口,还要关闭.除了console.log()其他命令没怎么用过,先在这里记一下,用到时在看看 一.显示信息的命令 consol ...

  9. libvirt保持虚拟机运行情况下修改名称

    通过virsh list命令能看到虚拟机的列表: [root@compute2 ~]# virsh list Id 名称 状态 ------------------------------------ ...

  10. 调度器&负载均衡调度算法整理

    一.Linux 调度器   Linux中进程调度器已经经过很多次改进了,目前核心调度器是在CFS(Completely Fair Scheduler),从2.6.23开始被作为默认调度器.用作者Ing ...