Skip to content

Instantly share code, notes, and snippets.

@ArrayIterator
Last active December 18, 2021 16:10
Show Gist options
  • Save ArrayIterator/156e38be0361dff6978d286cc72960b8 to your computer and use it in GitHub Desktop.
Save ArrayIterator/156e38be0361dff6978d286cc72960b8 to your computer and use it in GitHub Desktop.
php-fpm 8.0 + nginx server block.
server {
# http
listen 80;
# https
# pastikan sudah di deklarasi untuk
# ssl_certificate & ssl_certificate_key
# atau deklarasi server block ini
listen 443 ssl http2;
# block domain name
server_name example.com www.example.com;
# sertifikat ssl
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
# root directory
root /home/ubuntu/host/domain/public;
# web server index file
index index.php index.html index.htm;
# upload post max size, increase atau decrease sesuai kebutuhan
client_max_body_size 32M;
# location block
location / {
# index.php$is_args$args untuk rewrite
try_files $uri $uri/ /index.php$is_args$args;
}
# location block php handler
location ~ [^/]\.php(/|$) {
include fastcgi_params;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# rewrite request
try_files $fastcgi_script_name /index.php$is_args$args =404;
# fastcgi ke socket pool php-fpm
fastcgi_pass unix:/run/php/[email protected];
# buffer & misc
# buffer
fastcgi_buffer_size 16k;
fastcgi_buffers 256 32k;
# timedout rules
fastcgi_read_timeout 60; # tambahkan apabila proses PHP lebih dari 60 detik, tambahkan apabila kemungkinan proses upload lebih dari 60 detik
fastcgi_send_timeout 60;
fastcgi_intercept_errors off; # set ke off apabil ingin php untuk handle error
}
}
; apabila pm menggunakan static / dynamic, maka rekomendasi agar melakukan daemon reload setiap beberapa jam sekali via cron
; * */3 * * * /etc/init.d/php-fpm8.0 reload
; hanya rekomendasi untuk dapat menghapus operation cache / garbage collector di Memory.
; cron diatas untuk setiap 3 jam sekali.
; pool name
[[email protected]]
; Mandatory listen user & group script owner
; agar proses dapat membaca & menulis kode.
user = ubuntu
group = ubuntu
; pastikan sesuai dengan web server listener agar web server dapat mengakses socket
listen.owner = www-data
listen.group = www-data
; /run/php/nama-pool.sock
listen = /run/php/$pool.sock
; backlog
; listen.backlog = 1024
; Ganti pm jadi ondemand kalau ingin memperkecil resource usage tapi performa berkurang
;pm = ondemand
pm.process_idle_timeout = 10
pm = dynamic
; pm threading & processing, naikkan dengan kalkulasi
; process time * concurrent requests on process
; dengan catatan sesuaikan dengan resource.
pm.max_children = 20
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 10
; rekomendasi set perkiraan antara
; berapa detik bisa di proses vs concurrent request pada saat proses.
; 0 untuk untuk endless processing
; nilai untuk concurrent request / queue
; pm.max_requests = 0
; rekomendasi untuk terminate apabila lebih dari 300 seconds, menghindari memory overhead
; set sesuai kebutuhan atau set ke 0 untuk infinite
; request_terminate_timeout = 300
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment