NGINX配置文件配置信息

来吧,展示:

NGINX配置文件官方示例 NGINX
NGINX官方文档 NGINX


请注意:(上面内容为简化版,下面内容是详细配置信息,有些是上面没有的,如果你需要可以手动添加)

#   * For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/ *.conf;

worker_rlimit_nofile 65535;

events {
    use epoll;
    multi_accept on;
    worker_connections 65480;
}

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  /var/log/nginx/access.log  main;

    server_tokens	off;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    limit_req_zone $binary_remote_addr zone=addr:10m rate=50r/s;
    #limit_conn addr 100;
    gzip  on;
    gzip_disable “MSIE [1-6].(?!.*SV1);
    gzip_http_version 1.1;
    gzip_vary on;
    gzip_proxied any;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_comp_level 6;
    gzip_types text/plain text/css text/xml text/javascript application/json application/x-javascript application/xml application/xml+rss application/javascript;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # 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;
}

主配置配置文件讲解:


#   * For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;  #定义NGINX运行用户
worker_processes auto;  #启动进程,通常设置为和CPU数量相等或auto为自动
worker_cpu_affinity 0001 0010 0100 1000; #为每个进程分配CPU,例子中将8个进程分配到8个CPU,当然可以写多个,或者将一个进程分配到多个CPU
error_log /var/log/nginx/error.log; #全局错误日志,日志定义等级{debug|info|notice|warn|error|crit}
pid /var/run/nginx.pid;  #PID文件

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/ *.conf;

worker_rlimit_nofile 65535;  #NGINX进程打开最多文件描述符数目,理论值应该是最多打开文件数(ulimit -n)与NGINX进程数相处,但是NGINX分配请求不是那么均匀,所以最好与(ulimit -n)的值保持一致

#工作模式及连接上限
events {
    use epoll; #异步读写模型,是多路复用I/O中的一种方式,仅用于Linux2.6以上内核,可以大大提高NGINX的性能
    multi_accept on; #告诉NGINX尽可能的接受更多请求
    worker_connections 65480;  #单个后台Worker process进程的最大并发连接数(最大连接数=连接数*进程数)
}

#设定HTTP服务器,利用它的反向代理功能提供负载均衡支持
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  /var/log/nginx/access.log  main;  #设定日志格式

    server_tokens	off;  #隐藏返回NGINX版本信息
	autoindex          off;  #开启目录列表访问,适合下载服务器,默认关闭
    sendfile            on;  #sendfile指令指定Nginx是否调用sendfile函数(zero copy方式)来输出文件,对于普通应用必须设定为on,如果用来进行下载等应用磁盘I/O重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的uptime

    tcp_nopush          on;  #防止网络阻塞
    tcp_nodelay         on;  #提高数据的实时响应性
    keepalive_timeout   65;  #keepalive超时时间,客户端到服务器端的连接持续有效时间,当出现对服务器的后继请求时,keepalive-timeout功能可以避免建立或重新建立连接
    types_hash_max_size 2048;

    #以"$binary_remote_addr"为辨识获取钥匙,定义addr为限值域,10m为钥匙桶大小(10兆),50r/s为1次每秒
    limit_req_zone $binary_remote_addr zone=addr:10m rate=50r/s;
    #limit_conn addr 100;
    gzip  on;  #开启gzip压缩
    gzip_disable “MSIE [1-6].(?!.*SV1);  #关闭微软IE浏览器GZIP压缩,因为IE6对GZIP不友好
    gzip_http_version 1.1;  #压缩版本
    gzip_vary on;  #启用答应头"Vary: Accept-Encoding"
    gzip_proxied any;  #NGINX作为反向代理时启用,off(关闭所有代理结果的数据的压缩),expired(启用压缩,如果header头中包括"Expires"头信息),no-cache(启用压缩,header头中包含"Cache-Control:no-cache"),no-store(启用压缩,header头中包含"Cache-Control:no-store"),private(启用压缩,header头中包含"Cache-Control:private"),no_last_modefied(启用压缩,header头中不包含"Last-Modified"),no_etag(启用压缩,如果header头中不包含"Etag"头信息),auth(启用压缩,如果header头中包含"Authorization"头信息)
    gzip_min_length 1k;  #最小压缩
    gzip_buffers 4 16k;  #以16k为单位,按照原始数据大小以16k为单位的4倍申请内存
    gzip_comp_level 6;  #压缩级别大小,最大为9,值越小,压缩比例越小,CPU处理更快,值越大,消耗CPU越高
    gzip_types text/plain text/css text/xml text/javascript application/json application/x-javascript application/xml application/xml+rss application/javascript;  #匹配压缩类型
    
    client_max_body_size 10MB;  #允许客户请求的最大单文件字节数
    client_body_buffer_size 128KB;  #缓冲区代理缓存用户端请求的最大字节数
    proxy_connect_timeout 90;  #NGINX跟后端服务器连接超时时间(代理连接超时)
    proxy_send_timeout 90;  #后端服务器数据回传时间(代理发送超时)
    proxy_read_timeout 90;  #连接成功后,后端服务器响应时间(代理接收超时)
    proxy_buffer_size 4KB;  #设置代理服务器(NGINX)保存用户头信息的缓冲区大小
    proxy_buffers 4 32KB;  #proxy_buffers缓冲区,页面平均在32KB以下的话,这样设置
    proxy_busy_buffers_size 64KB;  #高负荷下缓存大小(proxy_buffers*2)
    large_client_header_buffers 4 4KB;  #设定请求缓存
    client_header_buffer_size 4KB;  #客户端请求头部的缓冲区大小,这个可以根据系统分页大小来设置,一般一个请求的头部大小不会超过1KB,不过由于一般系统分页都要大于1KB,所以这里设置为分页大小,分页大小可以用命令getconf PAGESIZE取得
    open_file_cach_max =1024 inactive=20s;  #这个将为打开文件指定缓存,默认是没有启用的,max指定缓存数量,建议和打开文件数一致,inactive是指经过多长时间文件没被请求后删除缓存
    open_file_cache_valid 30s;  #这个是指多长时间检查一次缓存的有效信息
    open_file_cache_min_user 1;  #open_file_cache指令中的inactive参数时间的最少使用次数,如果超过这个次数,文件描述符一直是在缓存中打开的, 如下例,如果有一个文件在inactive
    types_hash_max_size 2048;  #types_hash_max_size 影响散列表的冲突率。types_hash_max_size越大,就会消耗更多的内存,但散列key的冲突率会降低,检索速度就更快。types_hash_max_size越小,消耗的内存就越小,但散列key的冲突率可能上升
    

    include             /etc/nginx/mime.types;  #设置MIME类型,类型由mime.type文件定义
    default_type        application/octet-stream;  #避免浏览器自动播放文件,这个类型会让浏览器认为响应是普通的文件流,并提示用户下载文件

    # 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;  #包含其他配置文件,如自定义的虚拟主机
}

------------------------------------------------------END----------------------------------------------------------

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值