您的位置:首页 > 运维架构 > Nginx

Nginx配置文件优化实例与参数详解

2017-05-21 09:38 766 查看
user user group;    #用户和组

pid /var/run/nginx.pid;     #pid文件

worker_processes auto;  #nginx对外提供web服务时的worder进程数。

worker_rlimit_nofile 100000;    #worker进程的最大打开文件数限制

 

events {

    worker_connections 2048;    #一个worker进程同时打开的最大连接数

    multi_accept on;        #告诉nginx收到一个新连接通知后接受尽可能多的连接。

    use epoll;      #用于复用客户端线程的轮询方法。

}

 

http {

    server_tokens off;      #关闭在错误页面中的nginx版本数字

    sendfile on;       #sendfile()可以在磁盘和TCP socket之间互相拷贝数据。

    tcp_nopush on;  #一个数据包里发送所有头文件

    tcp_nodelay on;     #不要缓存数据

 

     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 off;     #nginx是否将存储访问日志

    error_log /var/log/nginx/error.log crit;    #nginx只能记录严重的错误

 

    keepalive_timeout 10;   # 给客户端分配keep-alive链接超时时间

    client_header_timeout 10;   #设置请求头和请求体(各自)的超时时间。

    client_body_timeout 10;     #设置请求头和请求体(各自)的超时时间。

    reset_timedout_connection on;   #告诉nginx关闭不响应的客户端连接

    send_timeout 10;    #指定客户端的响应超时时间。

 

    limit_conn_zone $binary_remote_addr zone=addr:5m;   #设置用于保存各种key(比如当前连接数)的共享内存的参数。

    limit_conn addr 100;    #给定的key设置最大连接数。

 

    include mime.types;

    default_type text/html;     #文件使用的默认的MIME-type。

    charset UTF-8;      #支持中文字符集

 

    gzip on;    #采用gzip压缩的形式发送数据

    gzip_disable "msie6";   #指定的客户端禁用gzip功能

    gzip_static on;    #压缩资源之前,先查找是否有预先gzip处理过的资源。

    gzip_proxied any;   #允许或者禁止压缩基于请求和响应的响应流

    gzip_min_length 1000;   #设置对数据启用压缩的最少字节数。

    gzip_comp_level 6;      #设置数据的压缩等级

    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;      #设置需要压缩的数据格式。

 

    open_file_cache max=100000 inactive=20s;    #打开缓存的同时也指定了缓存最大数目,以及缓存的时间。

    open_file_cache_valid 30s;      #在open_file_cache中指定检测正确信息的间隔时间

    open_file_cache_min_uses 2;     #定义了open_file_cache中指令参数不活动时间期间里最小的文件数。

    open_file_cache_errors on;      #指定了当搜索一个文件时是否缓存错误信息,也包括再次给配置中添加文件。

 

    fastcgi_connect_timeout 300;

    fstcgi_send_timeout 300;

    fstcgi_read_timeout 300;

    fastcgi_buffer_size 64k;

    fastcgi_buffers 4 64k;

    fastcgi_busy_buffers_size 128k;

    fstcgi_temp_file_write_size 128k;

    include /etc/nginx/conf.d/*.conf;

    include /etc/nginx/sites-enabled/*;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: