Nginx prelude

Pada dasarnya ketika kita sebagai orang awam melakukan tahap instalasi awal dari nginx web server, akan mengalami kesulitan untuk melakukan konfigurasi document root nya. Namun akan cukup mudah jika kita melakukan prosedur berikut ini :
1. Pastikan packages nginx dan php5 atau php5-fpm sudah terinstall dengan benar dan sesuai.
2. Lakukan backup pada berkas konfigurasi nginx di /etc/nginx/sites-available/default atau /etc/nginx/sites-available/server_kamu . Kosongkan, dan isi dengan parameter berikut :

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;
    # Jika ingin redirect seluruh request http ke https
    rewrite ^ https://$server_name$request_uri? permanent;
    root /<your_path_ddoc_root>;
    index index.php index.html index.htm;

    server_name server_domain_name_or_IP;

    location / {
        try_files $uri $uri/ =404;
        ### use this if your path of source is absolute /var/www/html : 
        ### try_files $uri $uri/ /index.php?$args;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /<your_path_doc_root>;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    # If u want to manage buffer or rendering like utube. But one thing, check with nginx -V module if  --with-http_mp4_module has been enabled.
    location /<path_directory_mp4>/ {
            limit_rate 260k; # about 2mbit
            limit_rate_after 3m;
            mp4;
            mp4_buffer_size 4M;
            mp4_max_buffer_size 10M;
     }

    if (!-e $request_filename){
        rewrite ^.*$ /index.php last;
    }
}

Jika kita menggunakan framework phalcon di nginx, maka ada beberapa penyesuaian seperti contoh berikut. Silahkan berkreasi.

server {
 listen 443;
 server_name tifosilinux.com 127.0.0.1;


 ssl on;
 ssl_certificate /etc/ssl/nginx/adminwarnet.crt;
 ssl_certificate_key /etc/ssl/nginx/adminwarnet.key;
 ssl_dhparam /etc/ssl/nginx/dhparam.pem;

ssl_session_cache shared:SSL:64m;
 ssl_session_timeout 15m;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
 ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
 ssl_prefer_server_ciphers on;
 add_header Strict-Transport-Security "max-age=0";
 ssl_stapling on;
 ssl_stapling_verify on;
 resolver 8.8.8.8 8.8.8.8 valid=3600s;
 resolver_timeout 5s;

index index.php index.html index.htm;
 #set $root_path '/var/www/html/upoint-op-dev/public';
 set $root_path '/var/www/html/';
 root $root_path;

location /up-op/ {
 set $root_path "$root_path/upoint-op-dev/public";
 try_files $uri $uri/ @up_op_rewrite;
 }

location @up_op_rewrite {
 rewrite ^/up-op/(.*)$ /index.php?_url=/$1;
 }

location ~ \.php($|/) {
 #try_files $uri =404;
 fastcgi_pass unix:/run/php/php5.6-fpm.sock;
 fastcgi_index index.php;
 fastcgi_split_path_info ^(.+\.php)(.*)$;
 fastcgi_param PATH_INFO $fastcgi_path_info;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 include fastcgi_params;
 }
 location ~ /\.ht {
 deny all;
 }

location ^~ /up-op {
 root /var/www/html/upoint-op-dev/public;
 try_files $uri $uri/ @rewrite;
 }

}

3. Simpan, restart, dan voila !!.

Untuk sebuah contoh, kita coba melakukan deployment phpmyadmin di lokasi /usr/share setelah melakukan instalasi dengan parameter apt-get (perhatikan bagian fastcgi_pass apakah kita menggunakan socket atau membuka port 9000):

server {
 location /phpmyadmin {
 root /usr/share/;
 index index.php index.html index.htm;
 location ~ ^/phpmyadmin/(.+\.php)$ {
 try_files $uri =404;
 root /usr/share/;
 #fastcgi_pass 127.0.0.1:9000;
 fastcgi_index index.php;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_split_path_info ^(.+\.php)(/.+)$;
 fastcgi_pass unix:/var/lib/php-fpm/b01.sock;
 include /etc/nginx/fastcgi_params;
 }
 location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
 root /usr/share/;
 }
 }
 location /phpMyAdmin {
 rewrite ^/* /phpmyadmin last;
 }
 }

Trims

Advertisements

Tinggalkan pesan atau komentar

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s