Memasang Nginx di Debian Wheezy

Nginx Logo

onta.uin-suka.ac.id (repo inta UIN Sunan Kalijaga) memasuki masa main tenis.

Job pertama : Upgrade database menggunakan MariaDB,
Job kedua : Migrasi webserver menggunakan nginx.

Langkah memasang :

1. Stop Apache2

root@onta:~# service apache2 stop

2. Hapus apache dan pasang nginx

root@onta:~# apt-get remove apache && apt-get install nginx

3. Jalankan Nginx, kemudian akses localhost (IP server)

root@onta:~#/etc/init.d/nginx start

4. Pasang PHP5 (untuk dukungan nginx dan php)

root@onta:~#apt-get install php5-fpm

5. Konfigurasi Nginx
Konfigurasi yang saya pakai mengesuaikan dari referensi [1] & [2]. Kurang lebih seperti ini :

user www-data;
worker_processes 5;
pid /var/run/nginx.pid;

# [ debug | info | notice | warn | error | crit ]
error_log  /var/log/nginx.error_log  info;

events {
        worker_connections 768;
}

http {
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 75 20;
        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        client_header_timeout  3m;
        client_body_timeout    3m;
        send_timeout           3m;

        client_header_buffer_size    1k;
        large_client_header_buffers  4 4k;

        gzip on;
        gzip_min_length  1100;
        gzip_buffers     4 8k;
        gzip_types       text/plain;

server {
        listen   80; ## listen for ipv4; this line is default and implied
        listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

        root /var/www;
        index index.php index.html index.htm;

        # Make site accessible from http://localhost/
        server_name localhost 172.16.7.2 onta.uin-suka.ac.id www.onta.uin-suka.ac.id;

        location / {
                try_files $uri $uri/ /index.html;
        }
    }
}

Simpan dan  reload nginx:

root@onta:~#/etc/init.d/nginx reload

Edit /etc/php5/fpm/php.ini…

root@onta:~#nano /etc/php5/fpm/php.ini
... dan set cgi.fix_pathinfo=0:
[...]
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting
; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://php.net/cgi.fix-pathinfo
cgi.fix_pathinfo=0
[...]

Reload PHP-FPM:

root@onta:~#/etc/init.d/php5-fpm reload

Oke, onta kelar main tenis dan sudah bisa dipakai kembali :))

Referensi
[0] http://www.howtoforge.com/installing-nginx-with-php5-and-php-fpm-and-mysql-support-lemp-on-debian-wheezy
[1] http://wiki.nginx.org/NginxFullExample
[2] http://wiki.nginx.org/NginxFullExample2

Regard
Tuan Pembual