Site icon Learning & Doing

Instalasi Nginx di Centos

[root@martin.server ~]# rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm

.:: install nginx

[root@martin.server ~]# yum install nginx

.:: konfigurasi nginx sebagai reverse proxy
buat file reverse proxy

[root@martin.server ~]# cd /etc/nginx/conf.d/

[root@martin.server conf.d]# nano proxy.conf

###isi dari file proxy.conf

proxy_redirect off;

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

client_max_body_size 10m;

client_body_buffer_size 128k;

proxy_connect_timeout 90;

proxy_send_timeout 90;

proxy_read_timeout 90;

proxy_buffers 32 4k;

.:: set-up proxy_pass pada vhost / nginx.conf

[root@martin.server ~]# cd /etc/nginx/conf.d/

[root@martin.server conf.d]# nano namadomain.com.conf

###isi dari file namadomain.com.conf

server {

listen 80;

server_name namadomain.com www.namadomain.com;

access_log /var/log/nginx/namadomain.com.access.log ;

error_log /var/log/nginx/namadomain.com.error.log ;

location / {

proxy_pass http://10.100.100.99:8080/ ; #ip web server

include /etc/nginx/conf.d/proxy.conf;

}

}

.:: testing konfigurasi dan restart nginx

[root@martin.server conf.d]# nginx -t

[root@martin.server conf.d]# /etc/init.d/nginx restart

.:: install rpaf module

mod_rpaf merupakan modul yang diperlukan untuk menerima IP sebenar daripada nginx.

Jika tanpa menggunaka module ini, webserver akan menerima ip dari server nginx.

[root@martin.server conf.d]# yum install mod_rpaf.x86_64

setelah install rpaf, pastikan di konfigurasi httpd.conf module ter-load

LoadModule rpaf_module /usr/lib64/httpd/modules/mod_rpaf-2.0.so

konfigurasi httpd.conf untuk menggunakan reverse proxy nginx

Listen 8080

.:: enable rpaf module pada vhost apache

[root@server01 ~]# nano /etc/httpd/conf/httpd.conf

### add these line in VirtualHost configuration

RPAFenable On

RPAFsethostname On

RPAFproxy_ips 10.100.100.99 ### can use multiple IP address

.:: restart apache

[root@server01 ~]# /etc/init.d/httpd restart

.:: cek port

[root@server01 ~]# netstat -tlnup |grep 80

tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 7640/nginx.conf

tcp 0 0 :::8080 :::* LISTEN 7654/httpd

testing

akses namadomain.com, seharusnya menunjukkan halaman dari apache, bukan halaman nginx

Sumber :

http://www.computesta.com/blog/2012/02/nginx-kelebihan-dibanding-apache/#.Us4e8vuK9KZ

http://www.wowrack.co.id/blog/nginx-sebagai-reverse-proxy/

Exit mobile version