Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have tried to search for a solution for this, but can't find any documentation/tips on my specific setup.

My setup:

Backendserver: ngnix: 2 different websites (2 top domains) in virtualenv, running gunicorn/python/django Backendserver hardware(VPS) 2gb ram, 8 CPU

Databaseserver: postgresql - pg_bouncer
Backendserver hardware (VPS) 1gb ram, 8 CPU

Varnishserver: only running varnish
Varnishserver hardware (VPS) 1gb ram, 8 CPU

I'm trying to set up a varnish server to handle rare spike in traffic (20 000 unique req/s) The spike happens when a tv program mention one of the sites.

What do I need to do, to make the varnish server cache both sites/domains on my backendserver?

My /etc/varnish/default.vcl :

backend django_backend {
    .host = "local.backendserver.com";
    .port = "8080";
}

My /usr/local/nginx/site-avaible/domain1.com

upstream gunicorn_domain1 {
    server unix:/home/<USER>/.virtualenvs/<DOMAIN1>/<APP1>/run/gunicorn.sock fail_timeout=0;

}

server {
    listen 80;
    listen 8080;
        server_name domain1.com;
        rewrite ^ http://www.domains.com$request_uri? permanent;
}

server {
    listen 80 default_server;
    listen 8080;

    client_max_body_size 4G;
    server_name  www.domain1.com;

    keepalive_timeout 5;

    # path for static files
    root /home/<USER>/<APP>-media/;

    location / {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;

      if (!-f $request_filename) {
        proxy_pass http://gunicorn_domain1;
        break;
      }
    }

}

My /usr/local/nginx/site-avaible/domain2.com

upstream gunicorn_domain2 {
    server unix:/home/<USER>/.virtualenvs/<DOMAIN2>/<APP2>/run/gunicorn.sock fail_timeout=0;

}

server {
    listen 80;
    listen 8080;
        server_name domain2.com;
        rewrite ^ http://www.domains.com$request_uri? permanent;
}

server {
    listen 80;
    listen 8080;

    client_max_body_size 4G;
    server_name  www.domain2.com;

    keepalive_timeout 5;

    # path for static files
    root /home/<USER>/<APP>-media/;

    location / {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;

      if (!-f $request_filename) {
        proxy_pass http://gunicorn_domain2;
        break;
      }
    }

}

Right now, If I try the Ip of the varnishserver I only get served domain1.com. Would everything be correct if I change the DNS of the two domain to point to the varnishserver, or is there extra setup before it would work?

Question 2: Do I need a dedicated server for varnish, or could I just install varnish on my backendserver, or would the server run out of memory quick?

share|improve this question
    
Answer 1 - At the moment if you request via an IP you'll get the first site returned in the config. To get the second domain you could switch their places in the config to test this. Answer 2 - Difficult to define need a dedicated server. It'll certainly make sense in terms of planning future resilience (load balancing etc.) if you have separate servers. Have you considered using NGINx as a front end proxy to Apache? (How to and why: digitalocean.com/community/articles/…) –  sgtbeano Nov 13 '13 at 15:21
3  
Why do you use varnish in front of nginx instead of nginx? Nginx has pretty rich caching feature set. –  VBart Nov 13 '13 at 15:35
    
@VBart Good point... I evaluated Varnish but nginx's caching does all I need. –  Michael Hampton Nov 13 '13 at 16:33
    
I have tested to change dns of two subdomains to the varnish server, and everything looks like its working. I'll look into caching just from nginx. –  Garreth 00 Nov 13 '13 at 16:43
    
@Garreth00: check for proxy_cache_* –  that guy from over there Nov 13 '13 at 23:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.