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代理缓存

posted @ 2018-05-21 18:38  你很棒  阅读(173)  评论(0编辑  收藏  举报