• nginx优化


    1.隐藏nginx版本号

    http {
    		server_tokens off;
    	}
    

    2.调整网络IO模型

    event {
    	use epoll;
    	}
    

    3.调整worker进程数量等于cpu核数

    worker_processes auto; 
    worker_cpu_affinity	auto;
    

    4.调整单个进程并发连接数,总并发=单个进程并发*进程数量

    events {
    	worker_connections 10000;
    }
    

    5.nginx的worker进程能打开的最大文件数(文件描述符)

    worker_rlimit_nofile 65535 
    
    #vim /etc/security/limits.conf 
    root soft nofile 65535		//针对root用户	soft提醒	hard限制	nofile文件数配置项  65535最大大小
    root hard nofile 65535 
    *	soft nofile 65535		//针对所有用户
    *	hard nofile 65535 
    
    

    6.连接超时时间,php程序设置短连接,java程序设置长连接

    http {
    	keepalive_timeout 65;
    	}
    

    7.gzip压缩

    http {
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 32k;
    #gzip_http_version 1.1;
    gzip_comp_level 9;
    gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
    gzip_vary on;
    gzip_disable "MSIE [1-6].";
    }
    

    8.expires静态文件缓存

    location ~ .*.(gif|jpg|jpeg|bmp|png|ico|txt|mp3|mp4|swf) {
            expires 15d;
        }
    location ~ .*.(html|css|js) {
            expires 12h;
        }
    
    

    9.nginx防盗链,referer

     location ~ .*.(gif|jpg|jpeg|bmp|png|ico|txt|mp3|mp4|swf)$ {
                    valid_referers none blocked *.wwang.xyz wwang.xyz;
                    if ($invalid_referer) {
                    return 403;
            }
            }
    

    10.禁止通过ip地址访问,禁止恶意域名解析,只允许域名访问

    server {
            listen 80 default_server;
            server_name _;
            return 501;
    }
    

    11.错误页面优雅显示

    server {
    	servername www.wwang.xyz;
    	error_page 404 /404.html;
    }
    

    12丶开启高效传输

    http {
    sendfile on;
    tcp_nopush on;
    	}
    

    13.https
    14.防CC攻击

    nginx模块:ngx_http_limit_conn_module  
    防CC的shell脚本
    LUA脚本
    

    15.nginx代理缓存

  • 相关阅读:
    12.python笔记之mysqldb模块
    13.python笔记之pyyaml模块
    11.python之线程,协程,进程,
    2.saltstack笔记之目标,模块,返回写入数据库
    6.django笔记之orm
    5.django笔记之form保存表单信息,动态select
    4.django笔记之admin
    docker批量删除none镜像
    docker 给none镜像打镜像
    jenkins卡在等待界面解决方法
  • 原文地址:https://www.cnblogs.com/lovelinux199075/p/9068688.html
Copyright © 2020-2023  润新知