Install varnish, nginx, with apache di kloxo, centos5.6


Pertama2 import repo dari epel

rpm -Uvh http://download.fedora.redhat.com/pub/epel/5Server/i386/epel-release-5-4.noarch.rpm

yum install nginx

lalu edit nginx.conf

nano /etc/nginx/nginx.conf

user nginx;
worker_processes 2;

error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;

pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main ‘$remote_addr – $remote_user [$time_local] $request ‘
‘”$status” $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for”‘;

access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;

gzip on;

# Load config files from the /etc/nginx/conf.d directory
include /etc/nginx/conf.d/*.conf;

#
# The default server
#
server {
listen 8080;

server_name default;

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

# Main location
location / {
proxy_pass http://127.0.0.1:8081; #Ganti 127.0.0.1 dengan ip vps
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_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
}
}

save terus check nginx nya

root$server~]:nginx -t

the configuration file /etc/nginx/nginx.conf syntax is ok

configuration file /etc/nginx/nginx.conf test is successful

Lalu install varnish vache

import repo varnish

rpm –nosignature -i http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release-3.0-1.noarch.rpm

terus install varnish via yum

yum install varnish

terus edit /etc/sysconfig/varnish

nano /etc/sysconfig/varnish

cari VARNISH_LISTEN_PORT=6081 // ganti port varnish 6081 menjadi 80

VARNISH_LISTEN_PORT=80

terus edit /etc/varnish/default.vcl

nano /etc/varnish/default.vcl

# This is a basic VCL configuration file for varnish. See the vcl(7)
# man page for details on VCL syntax and semantics.
#
# Default backend definition. Set this to point to your content
# server.
#
backend default {
.host = “127.0.0.1″; #ganti 127.0.0.1 sama ip vps anda
.port = “8080″; #port nginx
}
#
# Below is a commented-out copy of the default VCL logic. If you
# redefine any of these subroutines, the built-in logic will be
# appended to your code.
sub vcl_recv {
if (req.restarts == 0) {
if (req.http.x-forwarded-for) {
set req.http.X-Forwarded-For =
req.http.X-Forwarded-For + “, ” + client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
}
if (req.request != “GET” &&
req.request != “HEAD” &&
req.request != “PUT” &&
req.request != “POST” &&
req.request != “TRACE” &&
req.request != “OPTIONS” &&
req.request != “DELETE”winking {
/* Non-RFC2616 or CONNECT which is weird. */
return (pipe);
}
if (req.request != “GET” && req.request != “HEAD”winking {
/* We only deal with GET and HEAD by default */
return (pass);
}
if (req.http.Authorization || req.http.Cookie) {
/* Not cacheable by default */
return (pass);
}
return (lookup);
}

sub vcl_pipe {
# Note that only the first request to the backend will have
# X-Forwarded-For set. If you use X-Forwarded-For and want to
# have it set for all requests, make sure to have:
# set bereq.http.connection = “close”;
# here. It is not set by default as it might break some broken web
# applications, like IIS with NTLM authentication.
return (pipe);
}

sub vcl_pass {
return (pass);
}

sub vcl_hash {
hash_data(req.url);
if (req.http.host) {
hash_data(req.http.host);
} else {
hash_data(server.ip);
}
return (hash);
}

sub vcl_hit {
return (deliver);
}

sub vcl_miss {
return (fetch);
}

sub vcl_fetch {
if (beresp.ttl <= 0s ||
beresp.http.Set-Cookie ||
beresp.http.Vary == “*”winking {
/*
* Mark as “Hit-For-Pass” for the next 2 minutes
*/
set beresp.ttl = 120 s;
return (hit_for_pass);
}
return (deliver);
}

sub vcl_deliver {
return (deliver);
}

sub vcl_error {
set obj.http.Content-Type = “text/html; charset=utf-8″;
set obj.http.Retry-After = “5″;
synthetic {”
<?xml version=”1.0″ encoding=”utf-8″?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html>
<head>
<title>”} + obj.status + ” ” + obj.response + {“</title>
</head>
<body>
<h1>Error “} + obj.status + ” ” + obj.response + {“</h1>
<p>”} + obj.response + {“</p>
<h3>Guru Meditation:</h3>
<p>XID: “} + req.xid + {“</p>
<hr>
<p>Varnish cache server</p>
</body>
</html>
“};
return (deliver);
}

sub vcl_init {
return (ok);
}

sub vcl_fini {
return (ok);
}

Simpan

terus edit apache kloxo virtualhostnya

di /etc/httpd/conf/httpd.conf

Cari Listen 80 ganti menjadi

Listen 10.10.10.10:8081 #10.10.10.10 ganti dengan ip vps anda klo misalkan multy ip nya tambahkan saja listen nya contoh

Listen 0.0.0.0:8081

lalu edit /etc/httpd/conf/kloxo/default.conf

nano /etc/httpd/conf/kloxo/default.conf

<VirtualHost \
IPVPS1ANDA:8081\
IPVPS2ANDA:8081\
>
DocumentRoot /home/kloxo/httpd/default/
servername default
ServerAlias default.*
<Ifmodule mod_userdir.c>
Userdir “public_html”
</Ifmodule>
</VirtualHost>

edit /etc/httpd/conf/kloxo/init.conf

port nya menjadi 8081 yg ssl biarin aja

edit /etc/httpd/conf/kloxo/webmail.conf

ganti port 80 menjadi 8081

lalu liat /etc/httpd/conf/kloxo/virtualhost.conf

cat /etc/httpd/conf/kloxo/virtualhost.conf

ganti semua port 80 menjadi 8081 di

nano /home/httpd/domain.us/conf/kloxo.domain.us

klo suda selesai lalu

service httpd restart

service nginx restart

service varnish restart

Sekian dan terima kasi Semoga bermanfaat :D

Tags: , , ,

Comments & Responses

2 Responses so far.

  1. Kerriann says:

    You’re a real deep thniker. Thanks for sharing.

  2. Taron says:

    IMHO you’ve got the right awsner!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>