nginx 优化

nginx 优化

系统配置

//修改/etc/sysctl.conf
net.ipv4.tcp_syncookies = 1: 开启SYN Cookies。当出现SYN等待队列溢出时,启用cookies来处理,可防范少量SYN攻击,默认为0
net.ipv4.tcp_tw_reuse = 1: 开启重用。允许将TIME-WAIT sockets重新用于新的TCP连接,默认为0
net.ipv4.tcp_tw_recycle = 1: 开启TCP连接中TIME-WAIT sockets的快速回收,默认为0

//使配置生效
sysctl -p 

nginx配置

//全局配置
worker_processes  auto;
worker_cpu_affinity auto;
worker_rlimit_nofile 65535;
events {
	use epoll;
    worker_connections  10240;
}

image
linux修改文件句柄数

http配置

http {
	server_tokens off; 					
	sendfile        on;
	tcp_nopush on;  				
	keepalive_timeout  60;
	client_max_body_size 100m;
	gzip on;
	gzip_disable "msie6";
	gzip_proxied any;  				    
	gzip_min_length 1k;  				
	gzip_comp_level 5;  				
	gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;	
	gzip_vary on;						    
}

image

server配置

server {
	listen       8080;
    server_name  localhost;

	location /abc/ {
        proxy_read_timeout 240s;
        proxy_pass http://192.168.1.2:8088;
    }
}

image

参考文档

nginx优化大全

posted @ 2022-10-18 11:17  liwenchao1995  阅读(23)  评论(0编辑  收藏  举报