部分Nginx常用配置参数,没有补全还请见谅

...              #全局块
# user root;  #用户组
# worker_processes 2; #进程数配置
#pid /nginx/pid/nginx.pid;   #指定nginx进程运行文件存放地址
# error_log log/error.log debug;  #制定日志路径,级别。这个设置可以放入全局块,http块,server块,级别以此为:debug|info|notice|warn|error|crit|alert|emerg

events {         #events块
   ...
   # worker_connections  1024; #最大连接数 默认512
   # accept_mutex on;   #设置网路连接序列化,防止惊群现象发生,默认为on
   # multi_accept on;  #设置一个进程是否同时接受多个网络连接,默认为off
   # #use epoll;      #事件驱动模型,select|poll|kqueue|epoll|resig|/dev/poll|eventport
}

http      #http块
{
    ...   #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块。
    # underscores_in_headers on; #默认为off,忽略header name中的下划线
    # client_header_buffer_size 30m ; #如果(请求行+请求头)的大小如果没超过30m,放行请求。如果(请求行+请求头)的大小如果超过1k,则以large_client_header_buffers配置为准
    # large_client_header_buffers 4 30M; # 1.请求行(request line)的大小不能超过30m,
    				        2.请求头(request header)中的每一个头部字段的大小不能超过30,否则返回400错误(实际是494错误,但nginx统一返回400了),
                                           3.请求行+请求头)的大小不能超过120m(4 * 30m)
    # keepalive_timeout  0; #连接超时时间
    # gzip  on; #开启gzip压缩 如果没有开启gzip,用户访问我们的时候就是以原图来访问。
    # gzip_min_lenth 1k; #小于1K的文件不适合压缩,下限是1k
    # gzip_buffers 4 16k; #缓存的内存空间--4个16进制数据流
    # gzip_http_version 1.1;  #http版本
    # gzip_vary on;  #开启判断客户端和浏览器是否支持gzip
   
   upstream indexCalc  # 负载均衡,默认轮询ip,weight配置后根据权重优先                          			
    {
        server 192.168.31.9:8888;
        server 192.168.21.172:8888 backup; #热备
        # ip_hash; # 相同客服端则请求相同

        # 相关参数:1.down,表示当前的server暂时不参与负载均衡。
    	        2.backup,预留的备份机器。当其他所有的非backup机器出现故障或者忙的时候,才会请求backup机器,因此这台机器的压力最轻。
                   3.max_fails,允许请求失败的次数,默认为1。当超过最大次数时,返回proxy_next_upstream 模块定义的错误。
                   4.fail_timeout,在经历了max_fails次失败后,暂停服务的时间。max_fails可以和fail_timeout一起使用。

    }

        server        #server块 虚拟机主机配置
    {     	
        ...       #server全局块
        listen       80; #监听80端口
        server_name  localhost;   #定义使用 访问的网址
        #charset koi8-r;   #设置字符编码
        #access_log  logs/host.access.log  main;   #设定本虚拟主机的访问日志
        
        location [PATTERN]   #location块 (一般/,也可也添加后缀)
        {
            ...
            # 匹配任何请求,因为所有请求都是以"/"开始
            # 但是更长字符匹配或者正则表达式匹配会优先匹配
            root   html;#定义服务器的默认网站根目录位置 这个root目录其实就是/usr/local目录,alias 则是不带后缀的路径
            index  index.html index.htm; #定义首页索引文件的名称
        }
        #配置Nginx缓存
        location ~.*\.(jpg|png|gif)$ {
          expires 30d; #缓存存放30天,然后自动清除
        }
        location ~.*\.(css|js)? $ {
          expires 1h; #缓存存放1小时
        }

        #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;
        }
        # 对 “/” 启用反向代理,对上面的实例(后台服务)  
        location / {
          proxy_pass http://127.0.0.1:3000;  # 设置要代理的 uri,注意最后的 /。可以是 Unix 域套接字路径,也可以是正则表达式。
          proxy_redirect off; # 设置后端服务器“Location”响应头和“Refresh”响应头的替换文本
          proxy_set_header X-Real-IP $remote_addr; # 获取用户的真实 IP 地址
          #后端的Web服务器可以通过 X-Forwarded-For 获取用户真实IP,多个 nginx 反代的情况下,例如 CDN。参见:http://gong1208.iteye.com/blog/1559835 和 http://bbs.linuxtone.org/thread-9050-1-1.html
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          #以下是一些反向代理的配置,可选。
          proxy_set_header Host $host; # 允许重新定义或者添加发往后端服务器的请求头。
          client_max_body_size 10m; #允许客户端请求的最大单文件字节数
          client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数,
          proxy_connect_timeout 90; #nginx跟后端服务器连接超时时间(代理连接超时)
          proxy_send_timeout 90; #后端服务器数据回传时间(代理发送超时)
          proxy_read_timeout 90; #连接成功后,后端服务器响应时间(代理接收超时)
          proxy_buffer_size 4k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小
          proxy_buffers 4 32k; #proxy_buffers缓冲区,网页平均在32k以下的设置
          proxy_busy_buffers_size 64k; #高负荷下缓冲大小(proxy_buffers*2)
          proxy_temp_file_write_size 64k;
          #设定缓存文件夹大小,大于这个值,将从upstream服务器传
        }
         
    }
    server  
    {
      ...
      
    }
    ...     #http全局块
}