美文网首页
nginx静态文件json文件性能优化

nginx静态文件json文件性能优化

作者: FengZai8 | 来源:发表于2017-11-15 14:24 被阅读40次

    最近在爬的数据直接丢进nginx后台拿,拉的速度慢。。。
    于是开始简单优化一下。
    nginx version: nginx/1.13.6

    1. 修改 /etc/sysctl.conf文件
    net.core.somaxconn = 65536
    net.ipv4.tcp_max_tw_buckets = 1440000
    net.ipv4.ip_local_port_range = 1024 65000
    net.ipv4.tcp_fin_timeout = 15
    net.ipv4.tcp_window_scaling = 1
    net.ipv4.tcp_max_syn_backlog = 3240000
    
    1. 修改 /etc/security/limits.conf 文件
      soft nofile 4096 hard nofile 4096
    2. 修改 /etc/nginx/nginx.conf 文件
    user  nginx;
    worker_processes  2;
    
    error_log  /var/log/nginx/error.log warn;
    pid        /var/run/nginx.pid;
    
    events {
        worker_connections   65536;
        use epoll;
        multi_accept on;
    }
    
    http {
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;
    
        keepalive_timeout 65;
        keepalive_requests 100000;
        sendfile         on;
        tcp_nopush       on;
        tcp_nodelay      on;
    
        client_body_buffer_size    128k;
        client_max_body_size       10m;
        client_header_buffer_size    1k;
        large_client_header_buffers  4 4k;
        output_buffers   1 32k;
        postpone_output  1460;
    
        client_header_timeout  3m;
        client_body_timeout    3m;
        send_timeout           3m;
    
        open_file_cache max=1000 inactive=20s;
        open_file_cache_valid 30s;
        open_file_cache_min_uses 5;
        open_file_cache_errors off;
    
        gzip on;
        gzip_min_length  1000;
        gzip_buffers     4 4k;
        gzip_types       text/html application/x-javascript text/css application/javascript text/javascript text/plain text/xml application/json application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype application/x-font-ttf application/xml font/eot font/opentype font/otf image/svg+xml image/vnd.microsoft.icon;
        gzip_disable "MSIE [1-6]\.";
    
        # [ debug | info | notice | warn | error | crit | alert | emerg ]
        error_log  /var/log/nginx.error_log  warn;
    
        log_format main      '$remote_addr - $remote_user [$time_local]  '
          '"$request" $status $bytes_sent '
          '"$http_referer" "$http_user_agent" '
            '"$gzip_ratio"';
    
        log_format download  '$remote_addr - $remote_user [$time_local]  '
          '"$request" $status $bytes_sent '
          '"$http_referer" "$http_user_agent" '
            '"$http_range" "$sent_http_content_range"';
    
        map $status $loggable {
            ~^[23]  0;
            default 1;
        }
          include /etc/nginx/conf.d/*.conf;
    
        }
    }

    相关文章

      网友评论

          本文标题:nginx静态文件json文件性能优化

          本文链接:https://www.haomeiwen.com/subject/mwgcvxtx.html