Tags » Nginx

CakePHP Vhost for NGINX

First, configure PHP-FPM.


nano /etc/nginx/sites-available/your.site.com.conf
server {
 server_name your.site.com;
 listen 80;

index index.php index.html index.htm;
 root /var/www/vhosts/your.site.com/webroot;

 # CakePHP
 # main cakephp rewrite rule
 location / {
 try_files $uri $uri/ /index.php?$uri&$args;

location ~ .php$ {
 root /var/www/vhosts/your.site.com/webroot;
 try_files $uri =404;
 fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
 fastcgi_index index.php;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 include fastcgi_params;
 fastcgi_buffer_size 128k;
 fastcgi_buffers 256 4k;
 fastcgi_busy_buffers_size 256k;
 fastcgi_temp_file_write_size 256k;

location ~ /\.ht {
 deny all;

error_page 500 502 503 504 /50x.html;

 location = /50x.html {
 root /usr/share/nginx/html;

error_log /var/log/nginx/your.site.com.error.log;

# After:
# chmod -R 777 /var/www/vhosts/your.site.com/logs
# chmod -R 777 /var/www/vhosts/your.site.com/tmp/cache

PHP Site through NGINX

yum install php-fpm php-mysql
nano /etc/php-fpm.d/www.conf
listen = /var/run/php-fpm/php-fpm.sock
listen.owner = nobody
listen.group = nobody
user = nginx
group = nginx
php_value = 128M
php_value = 128M
php_value = 200
php_value = 'UTC'

chown -R nginx:nginx /usr/share/nginx/html

nano /etc/php.ini
; Dangerous when = 1

mkdir -p /var/lib/php_session_save
chown nginx:nginx /var/lib/php_session_save

nano /etc/nginx/sites-available/$VHOST.conf
ln -s /etc/nginx/sites-available/$VHOST.conf /etc/nginx/sites-enabled/$VHOST.conf

systemctl enable php-fpm
systemctl reload nginx
systemctl restart php-fpm

… 21 more words

robots.txt via nginx

Sebagai sebuah file statis, memang sudah seharusnya file robots.txt ditangani oleh nginx, berikut ini salah satu contoh config-nya:


location /robots.txt {
    alias /home/kholidfu/path/to/your/robots.txt;

Nginx Config for client_max_body_size in Opsworks

If you are still old school and are using Chef 11 in AWS Opsworks and you need to set “client_max_body_size” to a larger number than default add this to your layers custom json: 35 more words


Resize Image secara Dinamis via nginx

Install modul extras di Ubuntu:

sudo apt install nginx-extras

Tambahkan baris berikut di /etc/nginx/sites-available/default

location ~ ^/img(+)(?:/(.*))?$ {
        alias /path/to/images/dir/$2;
        image_filter_buffer 10M;
        image_filter resize $1 -;
    } 47 more words

Optimasi nginx

optimasi buffers

client_body_buffer_size 10K;
client_header_buffer_size 1k;
client_max_body_size 8m;
large_client_header_buffers 2 1k;

optimasi timeouts

client_body_timeout 12;
client_header_timeout 12;
keepalive_timeout 15;
send_timeout 10;

Gzip Compression

gzip             on;
gzip_comp_level  2;
gzip_min_length  1000;
gzip_proxied     expired no-cache no-store private auth;
gzip_types       text/plain application/x-javascript text/xml text/css application/xml; 22 more words