tweak nginx performance


nginx.conf

user www-data;  
 worker_processes auto;  
 pid /run/nginx.pid;  
 # Number of file descriptors used for Nginx. This is set in the OS with 'ulimit -n 200000'  
 # or using /etc/security/limits.conf  
 worker_rlimit_nofile 200000;  
 events {  
   worker_connections 4000;  
   multi_accept on;  
   # essential for linux, optmized to serve many clients with each thread  
   use epoll;  
 }  
 http {  
   ##  
   # Basic Settings  
   ##  
   sendfile on;  
   tcp_nopush on;  
   tcp_nodelay on;  
   keepalive_timeout 30;  
   keepalive_requests 100000;  
   reset_timedout_connection on;  
   client_body_timeout 10;  
   send_timeout 2;  
   # Caches information about open FDs, freqently accessed files.  
   open_file_cache max=200000 inactive=20s;  
   open_file_cache_valid 30s;  
   open_file_cache_min_uses 2;  
   open_file_cache_errors on;  
   client_max_body_size 100m;  
   types_hash_max_size 2048;  
   # server_tokens off;  
   # server_names_hash_bucket_size 64;  
   # server_name_in_redirect off;  
   include /etc/nginx/mime.types;  
   default_type application/octet-stream;  
   ##  
   # SSL Settings  
   ##  
   ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE  
   ssl_prefer_server_ciphers on;  
   ##  
   # Logging Settings  
   ##  
   access_log off;  
   error_log /var/log/nginx/error.log crit;  
   ##  
   # Gzip Settings  
   ##  
   gzip on;  
   gzip_disable "msie6";  
   gzip_min_length 10240;  
   gzip_proxied expired no-cache no-store private auth;  
   gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;  
   # gzip_vary on;  
   # gzip_proxied any;  
   # gzip_comp_level 6;  
   # gzip_buffers 16 8k;  
   # gzip_http_version 1.1;  
   # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;  
   ##  
   # Virtual Host Configs  
   ##  
   include /etc/nginx/conf.d/*.conf;  
   include /etc/nginx/sites-enabled/*;  
 }  
 #mail {  
 #  # See sample authentication script at:  
 #  # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript  
 #  
 #  # auth_http localhost/auth.php;  
 #  # pop3_capabilities "TOP" "USER";  
 #  # imap_capabilities "IMAP4rev1" "UIDPLUS";  
 #  
 #  server {  
 #    listen   localhost:110;  
 #    protocol  pop3;  
 #    proxy   on;  
 #  }  
 #  
 #  server {  
 #    listen   localhost:143;  
 #    protocol  imap;  
 #    proxy   on;  
 #  }  
 #}  
 daemon off; 

Nginx caching

 http {  
 proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=CACHE:10m inactive=90m max_size=1000m;  
 }  
 server {  
     location /cache {  
         # First attempt to serve request as file, then  
         # as directory, then fall back to index.html  
         try_files $uri $uri/ /index.php?q=$uri&$args;  
         proxy_pass       http://localhost:80;  
         proxy_set_header    Host $host;  
         proxy_cache      STATIC;  
         proxy_cache_valid   200 1d;  
         proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;  
     }  
 }

REF

Comments

Popular Posts