1. Tối ưu hóa nginx

- kiểm tra CPU

grep ^processor /proc/cpuinfo | wc -l

Thiết lập thông số theo công thức sau:

max_clients = worker_processes * worker_connections

# Ví dụ nếu có 16 core
worker_processes 16;
 
# kết nối cho mỗi worker
events
{
  worker_connections 4096;
  multi_accept on;
}

- Nén

gzip  on;
gzip_vary on;
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_disable "MSIE [1-6].";

- Bật caching cho client

location ~* .(jpg|jpeg|gif|png|css|js|ico|xml)$ {
         access_log        off;
         log_not_found     off;
         expires           30d;
     }


open_file_cache          max=2000 inactive=20s;
open_file_cache_valid    60s;
open_file_cache_min_uses 5;
open_file_cache_errors   off;


Tối ưu hóa cho php

# execute all .php files via php-fpm
        location ~ .php$ {
            # connect to a unix domain-socket:
            fastcgi_pass   unix:/var/run/php5-fpm.sock;
            fastcgi_index  index.php;

            fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;

            fastcgi_buffer_size 128k;
            fastcgi_buffers 256 16k;
            fastcgi_busy_buffers_size 256k;
            fastcgi_temp_file_write_size 256k;

            # This file is present on Debian systems..
            include fastcgi_params;
        }

2. Tối ưu hóa php-fpm

file php-fpm.conf  thêm/sửa:

emergency_restart_threshold 10
emergency_restart_interval 1m
process_control_timeout 10sCập nhật lần cuối ngày 21/01/2016 Ngày đăng: