title: Simple Configuration Nginx and Varnish
body: <p>I have 3 computers on same network(LAN). And I want to configure one computer as Nginx Web-Server, and another as Varnish Cache server and one client . I succesfully installed one(let's say A) Nginx ( 192.168.0.15 ) and B Varnish( 192.168.0.20 ). I configured  A  as a webserver and I can browse the index.html from other computers. But I couldn't connect it with B.
  I messed up with "nginx.conf" and "/sites-available/server.com" and Varnish's "default.vcl"</p>
  
  <p>Could you give me the basic configurations which suit my environment ?</p>
  
  <p>If you want to take a look
  My nginx.conf :</p>
  
  <pre><code>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;
  
      keepalive_timeout  65;
  
      #gzip  on;
      include /etc/nginx/conf.d/*.conf;
  
      upstream dynamic_node {
              server 1.1.1.1:80; # 1.1.1.1 is the IP of the Dynamic Node
          }
      server {
          listen      81;
          server_name  myserver.myhome.com;
          location / {
          #root /var/www/server.com/public_html;
          #index index.html index.htm;
  
          # pass the request on to Varnish
          proxy_pass http://192.168.0.20;
  
          # Pass a bunch of headers to the downstream server.
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  
          proxy_redirect     off; 
          }
      }
  }
  </code></pre>
  
  <p>/sites-available/server.com :</p>
  
  <p>server {</p>
  
  <pre><code>listen   80;
  server_name myserver.myhome.com;
  
  access_log /var/www/server.com/access.log;
  error_log /var/www/server.com/error.log;
  </code></pre>
  
  <p>}</p>
  
  <p>And default.vcl like this :</p>
  
  <pre><code>backend web1 {
      .host = "192.168.0.15";
      .port = "8080";
  }
  sub vcl_recv {
      if (req.http.host == "192.168.0.15") {
  
          #set req.http.host = "myserver.myhome.com";
          set req.backend = web1;
      }   
  }
  </code></pre>
  
  <p>Lastly  /etc/default/varnish :</p>
  
  <pre><code>DAEMON_OPTS="-a :6081 \
               -T localhost:6082 \
               -f /etc/varnish/default.vcl \
               -S /etc/varnish/secret \
               -s malloc,256m"
  </code></pre>
  
  <p>Thanks in advance :)</p>