Chia Sẽ Kinh Nghiệm Về IT



Tìm Kiếm Với Google
-


Gởi Ðề Tài Mới  Gửi trả lời
 
Công Cụ Xếp Bài
Tuổi 18-06-2014, 09:18 AM   #1
hoctinhoc
Guest
 
Trả Lời: n/a
How to setup an ultra-fast CDN using Nginx and Varnish
How to setup an ultra-fast CDN using Nginx and Varnish


GIT - If your website takes more than 3 seconds to load, there is a big chance to loose your site visitors and that is a risk we are dealing with today due to the big competition in the industry. There are lots of reasons which effects on the site’s speed.
  1. Large multimedia contents
  2. DNS look up issue
  3. Server response time
  4. Multiple redirects
are few from a lengthy list.

If you are using a good CDNs to serve contents, then that will give a good boost while loading the site.

Installing Nginx and varnish
  1. apt-get install nginx
  2. apt-get install varnish
Nginx Config
  • (/etc/nginx/sites-enabled/default)
server {
open_file_cache_valid 20m;
listen 81;
server_name mydomain.com;
access_log /var/log/cdn/mydomain.com/logs/access.log;
root /cdn_document_path/;
location ~* \.(gif|jpg|jpeg|png|wmv|avi|mpg|mpeg|mp4|htm|html| js|css|mp3|swf|ico|flv)$ {
open_file_cache_valid 120m;
expires 7d;
open_file_cache max=1000 inactive=20s
}location = /50x.html {
root /var/www/nginx-default;
}# No access to .htaccess files.
location ~ /\.ht {
deny all;
}
}
Varnish Config
  • (/etc/default/varnish)
START=yes
NFILES=131072
MEMLOCK=82000
INSTANCE=$(uname -n)
DAEMON_OPTS=”-a :80 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s file,/var/lib/varnish/$INSTANCE/varnish_storage.bin,1G”
  • (/etc/varnish/default.vcl)
backend default {
.host = “127.0.0.1″;
.port = “81″;
}sub vcl_recv {
if (req.url ~ “\.(js|css|jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|o gg|swf)$”) {
return (lookup);
}
}sub vcl_fetch {
if (req.url ~ “\.(js|css|jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|o gg|swf)$”) {
unset obj.http.set-cookie;
}
}
Start Nginx and Varnish
  1. /etc/init.d/nginx start
  2. /etc/init.d/varnish restart
Once you start Nginx and Varnish. Varnish will start to server port 80 web traffic. If it is a static content varnish will server and nginx will look after all dynamic contents.

  Trả lời ngay kèm theo trích dẫn này
Gửi trả lời


Công Cụ
Xếp Bài

Quyền Hạn Của Bạn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Hình Cảm xúc đang Mở
[IMG] đang Mở
Mã HTML đang Tắt




Bây giờ là 02:32 AM. Giờ GMT +7



Diễn đàn tin học QuantriNet
quantrinet.com | quantrimang.co.cc
Founded by Trương Văn Phương | Developed by QuantriNet's members.
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.