Varnish + NGINX

Support/Development for PHP
kram
Forum Regular
Forum Regular
Posts: 243
Joined: Sat Dec 11, 2004 2:33 pm
Location: South Africa

Varnish + NGINX

Unread post by kram »

Hello,

Has anybody attempted or successfully completed an implementation of both Varnish + NGINX on Centos 5 using PHP 5.3+?

:?: + :idea:
Mark Brindley
2Large Networks - Web solutions that work
kram
Forum Regular
Forum Regular
Posts: 243
Joined: Sat Dec 11, 2004 2:33 pm
Location: South Africa

Re: Varnish + NGINX

Unread post by kram »

In the pursuit of ridiculous “server speed” (happiness), I decided to give this a whirl today.
Setting up Varnish was not all that hard, battled through the code a bit and emerged on the other side with a semi-working solution.
I would appreciate any tips or suggestion to fully complete and implement the solution.

Where I stand:

Working Nginx using atomic-accelerator

Varnish running but on port 6081 – what I need is nginx to connect to port 6081 instead of 8080

Nginx: http://www.2large.co.za/
see: http://redbot.org/?uri=http%3A%2F%2Fwww.2large.co.za
Server: nginx/1.0.0
X-Powered-By: PleskLin

Nginx + Varnish: http://www.2large.co.za:6081
see: http://redbot.org/?uri=http%3A%2F%2Fwww ... .za%3A6081
Server: nginx/1.0.0
Via: 1.1 varnish

Conf files Varnish

/etc/sysconfig/varnish

# # Default address and port to bind to
# # Blank address means all IPv4 and IPv6 interfaces, otherwise specify
# # a host name, an IPv4 dotted quad, or an IPv6 address in brackets.
VARNISH_LISTEN_ADDRESS=0.0.0.0
VARNISH_LISTEN_PORT=6081

vi /etc/varnish/default.vcl

backend default {
.host = "127.0.0.1";
.port = "80";
}

NGINX Conf

vi /etc/nginx/nginx.conf
resolver 127.0.0.1;
include /etc/nginx/conf.d/*.conf;

/etc/nginx/conf.d/2large.co.za.conf

server {
listen 80;
server_name 2large.co.za http : // w w w.2large.co.za;

netstat –ntpl

tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 27396/nginx.conf
tcp 0 0 :::8080 :::* LISTEN 4953/httpd
tcp 0 0 0.0.0.0:6081 0.0.0.0:* LISTEN 10448/varnishd

ps auwx | grep varnish

varnish 26641 0.0 0.0 1335776 10860 ? Sl 22:40 0:03 /usr/sbin/varnishd -P /var/run/varnish.pid -a :6081 -f /etc/varnish/default.vcl -T 127.0.0.1:6082 -t 120 -w 1,1000,120 -u varnish -g varnish -S /etc/varnish/secret -s file,/var/lib/varnish/varnish_storage.bin,1G

varnishlog

15 ReqStart c 41.185.108.125 4009 1256145342
15 RxRequest c GET
15 RxURL c /images/stories/slide/5gb-hosting.png
15 RxProtocol c HTTP/1.1
15 RxHeader c Host: http : // w w w .2large.co.za:6081
15 RxHeader c User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0
15 RxHeader c Accept: image/png,image/*;q=0.8,*/*;q=0.5
15 RxHeader c Accept-Language: en-gb,en;q=0.5
15 RxHeader c Accept-Encoding: gzip, deflate
15 RxHeader c Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
15 RxHeader c Connection: keep-alive
15 RxHeader c Referer: http : // w w w.2large.co.za:6081/
15 RxHeader c If-Modified-Since: Sun, 26 Jun 2011 15:46:03 GMT
15 RxHeader c Cache-Control: max-age=0
15 VCL_call c recv pass
15 VCL_call c hash
15 Hash c /images/stories/slide/5gb-hosting.png
15 Hash c http : // w w w .2large.co.za:6081
15 VCL_return c hash
15 VCL_call c pass pass
15 Backend c 13 default default
15 TTL c 1256145342 RFC 120 1309991102 0 0 0 0
15 VCL_call c fetch hit_for_pass
15 ObjProtocol c HTTP/1.1
15 ObjResponse c Not Modified
15 ObjHeader c Server: nginx/1.0.0
15 ObjHeader c Date: Wed, 06 Jul 2011 22:25:01 GMT
15 ObjHeader c Last-Modified: Sun, 26 Jun 2011 15:46:03 GMT
15 ObjHeader c Expires: Fri, 05 Aug 2011 22:25:01 GMT
15 ObjHeader c Cache-Control: max-age=2592000
15 VCL_call c deliver deliver
15 TxProtocol c HTTP/1.1
15 TxStatus c 304
15 TxResponse c Not Modified
15 TxHeader c Server: nginx/1.0.0
15 TxHeader c Last-Modified: Sun, 26 Jun 2011 15:46:03 GMT
15 TxHeader c Expires: Fri, 05 Aug 2011 22:25:01 GMT
15 TxHeader c Cache-Control: max-age=2592000
15 TxHeader c Accept-Ranges: bytes
15 TxHeader c Date: Wed, 06 Jul 2011 22:25:02 GMT
15 TxHeader c X-Varnish: 1256145342
15 TxHeader c Age: 0
15 TxHeader c Via: 1.1 varnish
15 TxHeader c Connection: keep-alive
Mark Brindley
2Large Networks - Web solutions that work
dayo
Forum Regular
Forum Regular
Posts: 158
Joined: Sun Jul 12, 2009 1:33 pm

Re: Varnish + NGINX

Unread post by dayo »

There is what seems to be a peripheral benefit to such a configuration that makes it attract some attention but alas! it is but a waste of time.

Anything that can be done with Varnish + Nginx can be done faster and better with Nginx alone.
kram
Forum Regular
Forum Regular
Posts: 243
Joined: Sat Dec 11, 2004 2:33 pm
Location: South Africa

Re: Varnish + NGINX

Unread post by kram »

@dayo - any pointers on tweaking Nginx would be greatly appreciated.
Mark Brindley
2Large Networks - Web solutions that work
dayo
Forum Regular
Forum Regular
Posts: 158
Joined: Sun Jul 12, 2009 1:33 pm

Re: Varnish + NGINX

Unread post by dayo »

Hi.

That is a bit broad as there are a host of factors to consider specific to your requirements.

However, I gave some tips in the original nginx announcements on this forum at: http://atomicorp.com/forums/viewtopic.p ... 5&start=15.

This would be a reasonable point to start from as a basic "proxy all to Apache" setup although I assume this is what the accelerator already applies. I can't say for certain as I do longer use ASL, the accelerator and/or Plesk and now compile my own version of Nginx.

Also, some of my recommendations would be different today (no "Static files" location as this approach has been deprecated) etc.
Post Reply