Linux

Konfig Nginx untuk Website Super Cepat #327

try hard adalah mencoba keras

andrypein.net : Sebenarnya ini konfig nginx php-fpm mysql resep racikan sendiri dengan referensi dari web, forum dan trial error pribadi.

Pertama-tama : Jangan Percaya dengan konfigurasi yang di share dimanapun itu sumbernya, semuanya racik dan trial error sendiri, termasuk jgn percaya konfigan yang saya share dibawah ini, wkwkkwkw tapi kalau mau coba silahkan.

Btw, ini konfigan karena dulu nge-admin server dengan high load daily traffic yang bernama fokusjabar.

Semuanya dicoba, mulai dari cpanel klasik lalu migrasi karena tidak keren, coba apache sangat BERAT, akhirnya jatuh di nginx yang GG.

Alasan pakai nginx sangat sederhana karena “WARNA FAVORIT SAYA HIJAU“.

Meanwhile konfigan yg akan dishare kali ini belum mendukung https, maklum lah jadul, masih coba-coba tuning sana sini hingga akhirnya aing punya ramuan sendiri supaya website menjadi FAST.

Pernah juga eksperimen memakai apache sebagai backend lalu nginx sebagai frontend, namun mendengar apache saja saya sudah geli, karena dia tidak hijau dan rakus memory.

Okay, kalau begitu ini konfigan lengkapnya :

ini untuk mysql di /etc/mysql/my.cnf

connect_timeout     = 10
wait_timeout        = 30
interactive_timeout = 30
key_buffer          = 16K
max_allowed_packet  = 1M
thread_stack        = 64K
thread_cache_size   = 1
sort_buffer         = 128K
net_buffer_length   = 2K

# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched

myisam-recover      = BACKUP
max_connections     = 150
table_cache         = 4
#thread_concurrency = 10

#
# * Query Cache Configuration
#
query_cache_limit       = 1M
sort_buffer_size        = 64K
innodb_buffer_pool_size = 128M

#tuned by pein

read_buffer_size        = 256K
read_rnd_buffer_size    = 256K
query_cache_size        = 16M
tmp_table_size          = 128M
max_heap_table_size     = 128M
table_open_cache        = 300
table_cache             = 4

Lalu konfig php-fpm.conf di /etc/php5/fpm/php-fpm.conf

emergency_restart_threshold = 10
emergency_restart_interval = 1m
process_control_timeout = 10
process.max = 150
rlimit_core = 1
events.mechanism = epoll

Konfig www.conf (global default) /etc/php5/fpm/pool.d/www.conf

;listen = /var/run/php5-fpm.sock
listen = 127.0.0.1:7777
listen.backlog = 65535
listen.mode = 0660
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 10
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 4
pm.process_idle_timeout = 10 
pm.max_requests = 500
request_terminate_timeout = 120s
rlimit_files = 131072
rlimit_core = 2
catch_workers_output = yes

Konfig nginx default /etc/nginx/sites-available/default

server {
    server_name www.domainmu.com domainmu.com; 
    root /home/bebas;
    index index.php;

    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt  { log_not_found off; access_log off; }


    location ~ .php$ {
    try_files $uri =404; 
    include fastcgi_params;
    fastcgi_pass 127.0.0.1:7777;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_connect_timeout 60;
    fastcgi_send_timeout 600;
    fastcgi_read_timeout 600;
    fastcgi_intercept_errors on;
    }   


    location ~ /. {
        deny  all;
        access_log off;
        log_not_found off;
    }


}

Terakhir konfig nginx.conf di /etc/nginx/nginx.conf

user www-data;
worker_processes 4; #sesuaikan dengan prosesor VPS atau dedi server
pid /run/nginx.pid;

events {
  worker_connections 8192;
  multi_accept on;
  use epoll;
}

http {

 ##
 # Basic Settings
 ##

 #set_real_ip_from 127.0.0.1;
 #real_ip_header X-Forwarded-For;

 sendfile on;
 sendfile_max_chunk 512k;
 tcp_nopush on;
 tcp_nodelay on;
 keepalive_timeout 15;
 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 /var/log/nginx/access.log;
 error_log /var/log/nginx/error.log;

 gzip on;
 gzip_disable "msie6";
 gzip_vary on;
 gzip_proxied any;
 gzip_comp_level 6;
 gzip_min_length 1024;
 gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascrip$
 gzip_buffers 64 8k;
 gzip_http_version 1.1;
 ignore_invalid_headers on;
 client_max_body_size    15m;
 client_body_buffer_size 10k;
 client_header_timeout  600;
 client_body_timeout 600;
 send_timeout    600;
 connection_pool_size  256;
 client_header_buffer_size 2k;
 large_client_header_buffers 4 16k;
 request_pool_size  4k;
 output_buffers   4 32k;
 postpone_output  1460;

 ##
 # Virtual Host Configs
 ##

 include /etc/nginx/conf.d/*.conf;
 include /etc/nginx/sites-enabled/*;
}

Serius, itu masih kurang maksimal, apalagi teknologi sekarang semakin maju dengan adanya docker.

Alhamdulillah aing mengikuti dua-duanya dan bisa konfig tuning website menjadi sangat cepat mau itu docker atau non-docker.

Kaya web aing sekarang, kemarin-kemarin masih non docker alias stack dari nginx+fpm+mysql+wp+redis sekarang mah containered dongs.

*AFK

Related Articles

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *

Check Also
Close
Back to top button