{ "created": "2015-12-20T19:56:54Z", "hierarchy": [ { "name": "ROOT", "type": "folder", "uri": "/ROOT" }, { "name": "Varnish", "type": "article", "uri": "Varnish" } ], "html": "\n\n \n \n \n \n\n \n \n\n \n \n \n \n \n\n Varnish\n\n \n \n \n \n
\n
\n \n
\n
\n \n \n\n\n

Varnish

\n\n \n

Pre-Flight

\n
# Install the repo  \nrpm -ivh http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.noarch.rpm\n  \n# Install Varnish  \nyum -y install varnish  \n  \n# Make copy of config  \ncp /etc/varnish/default.vcl{,.original}\n
\n

Can now start a varnish daemon with varnishd and specify the start\nparams like the documentation asks you to\ndo.\nBut will use init daemons and sysconfig options on a RHEL box, which is\nneater.

\n

Edit /etc/sysconfig/varnish. Changed some default options:

\n
# Listen on all addresses, on the HTTP port  \nVARNISH_LISTEN_ADDRESS=  \nVARNISH_LISTEN_PORT=80  \n\n# Use a 250MB cache  \nVARNISH_STORAGE_SIZE=250M  \n       \n# Use malloc  \nVARNISH_STORAGE="malloc,${VARNISH_STORAGE_SIZE}"\n
\n

Both “file” and “malloc” use disk and memory, but in different\nways.

\n

This is the plan:

\n
World ---> Varnish ---> Nginx ---> Application Server  \n           0.0.0.0:80  \n                        127.0.0.1:8080  \n                                   127.0.0.1:9090\n
\n

In this case, the Nginx server is considered a “backend server” from\nwhich Varnish can request and then get data. I defined a simple one in\n/etc/varnish/default.vcl

\n
# Define a simple Nginx backend\nbackend nginx_server {\n        .host = "localhost";\n        .port = "8080";\n}\n
\n

Restarted the varnish and nginx services, made sure they were listening\non the right ports.

\n
[root@example conf.d]# netstat -tunlp | grep 80  \ntcp  0   0 0.0.0.0:80        0.0.0.0:*     LISTEN   27090/varnishd  \ntcp  0   0 127.0.0.1:8080    0.0.0.0:*     LISTEN   26861/nginx\n
\n

The site should now work exactly as before. A few notes:

\n\n

Methods

\n

vcl_recv

\n

The entry point. I played around with the default subroutine by simply\nadding this to default.vcl and restarting Varnish:

\n
sub vcl_recv {\n    # Check for a standard HTTP verb. If none used, bark.\n    if (req.request != "GET") {\n            error 400 "I don't understand what you want me to do.";\n    }\n}\n
\n

After that, a simple curl -X POST nikhil.io yielded:

\n
<?xml version="1.0" encoding="utf-8"?>\n<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\n "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n<html>\n  <head>\n    *<title>400 I don't understand what you want me to do.</title>*\n  </head>\n  <body>\n    <h1>Error 400 I don't understand what you want me to do.</h1>\n    <p>I don't understand what you want me to do.</p>\n    <h3>Guru Meditation:</h3>\n    <p>XID: 2033234310</p>\n    <hr>\n    <p>Varnish cache server</p>\n  </body>\n</html>\n
\n

Nice.

\n

vcl_hash

\n

Varnish uses a key-value memory map. This subroutine defines how the key\nis generated. By default, it uses (URL or IP) + hostname.

\n

vcl_pipe and vcl_pass

\n

Called when return(pipe) or return(pass) are… returned from\nvcl_recv.

\n

In pipe mode is the simplest “Varnish-bypass” mode, where it\nshort-circuits the connection between the client and the backend. No\ncaching, no logging. Varnish does nothing while client speaks to backend\n(still through Varnish.)

\n

In pass mode, Varnish can look at (and manipulate) request and response\ndata

\n

vcl_fetch

\n\n

   varnishd -C -f /etc/varnish/default.vcl

\n\n\n\n
\n \n
\n \n \n \n \n \n\n", "id": "641abe6b-a419-514c-baef-9cd40c36d7f6", "modified": "2022-06-13T23:23:48Z", "revisions": [ { "authorEmail": "mail@nikhil.io", "authorName": "Nikhil Anand", "date": "2022-06-13T23:23:48Z", "id": "6be928c4c8de048934c03e3c61539c9ceec7d59a", "shortId": "6be928c4", "subject": "Update config.yml", "content": "* The flowchart's really helpful in visualizing how Varnish handles a\n request before asking the backend.\n* `default.vcl` comes with commented out subroutines which are worth\n a study.\n * I commented the hell out of them in this repo.\n* Test code with\n\n varnishd -C -f /etc/varnish/default.vcl\n\nPre-Flight\n----------\n\n # Install the repo \n rpm -ivh http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.noarch.rpm\n \n # Install Varnish \n yum -y install varnish \n \n # Make copy of config \n cp /etc/varnish/default.vcl{,.original}\n\nCan now start a varnish daemon with `varnishd` and specify the start\nparams [like the documentation asks you to\ndo](https://www.varnish-cache.org/docs/3.0/tutorial/starting_varnish.html).\nBut will use init daemons and sysconfig options on a RHEL box, which is\nneater.\n\nEdit `/etc/sysconfig/varnish`. Changed some default options:\n\n # Listen on all addresses, on the HTTP port \n VARNISH_LISTEN_ADDRESS= \n VARNISH_LISTEN_PORT=80 \n \n # Use a 250MB cache \n VARNISH_STORAGE_SIZE=250M \n       \n # Use malloc \n VARNISH_STORAGE=\"malloc,${VARNISH_STORAGE_SIZE}\"\n\nBoth \"file\" and \"malloc\" use disk and memory, [but in different\nways](https://www.varnish-software.com/static/book/Tuning.html#storage-backends).\n\nThis is the plan:\n\n World ---> Varnish ---> Nginx ---> Application Server \n            0.0.0.0:80 \n                         127.0.0.1:8080 \n                                    127.0.0.1:9090\n\nIn this case, the Nginx server is considered a \"backend server\" from\nwhich Varnish can request and then get data. I defined a simple one in\n`/etc/varnish/default.vcl`\n\n # Define a simple Nginx backend\n backend nginx_server {\n .host = \"localhost\";\n .port = \"8080\";\n }\n\nRestarted the varnish and nginx services, made sure they were listening\non the right ports.\n\n [root@example conf.d]# netstat -tunlp | grep 80 \n tcp  0   0 0.0.0.0:80        0.0.0.0:*     LISTEN   27090/varnishd \n tcp  0   0 127.0.0.1:8080    0.0.0.0:*     LISTEN   26861/nginx\n\nThe site should now work exactly as before. A few notes:\n\n* There's no caching taking place. Yet. That's where the VCL\n [DSL](http://en.wikipedia.org/wiki/Domain-specific_language)\n comes in.\n* Since I only have one server, I'm not interested in Varnish's\n load-balancing capabilities.\n\nMethods\n-------\n\n### vcl\\_recv\n\nThe entry point. I played around with the default subroutine by simply\nadding this to `default.vcl` and restarting Varnish:\n\n sub vcl_recv {\n # Check for a standard HTTP verb. If none used, bark.\n if (req.request != \"GET\") {\n error 400 \"I don't understand what you want me to do.\";\n }\n }\n\nAfter that, a simple `curl -X POST nikhil.io` yielded:\n\n \n \n \n \n *400 I don't understand what you want me to do.*\n \n \n

Error 400 I don't understand what you want me to do.

\n

I don't understand what you want me to do.

\n

Guru Meditation:

\n

XID: 2033234310

\n
\n

Varnish cache server

\n \n \n\nNice.\n\n### vcl\\_hash\n\nVarnish uses a key-value memory map. This subroutine defines how the key\nis generated. By default, it uses (URL or IP) + hostname.\n\n### vcl\\_pipe and vcl\\_pass\n\nCalled when `return(pipe)` or `return(pass)` are... returned from\n`vcl_recv`.\n\nIn pipe mode is the simplest \"Varnish-bypass\" mode, where it\nshort-circuits the connection between the client and the backend. No\ncaching, no logging. Varnish does nothing while client speaks to backend\n(still through Varnish.)\n\nIn pass mode, Varnish can look at (and manipulate) request and response\ndata\n\n### vcl\\_fetch\n\n* A full restart wipes the cache: neither \"file\" nor \"malloc\"\n are persistent.\n* You can see how Varnish translates the VCL into C code by:\n\n`   varnishd -C -f /etc/varnish/default.vcl`\n\n* Here's a useful [list of\n actions](https://www.varnish-cache.org/docs/3.0/tutorial/vcl.html#actions).\n" }, { "authorEmail": "mail@nikhil.io", "authorName": "Nikhil Anand", "date": "2015-12-27T07:27:56Z", "id": "5a5b1a32f41081d062ab86f8869a961bcad79668", "shortId": "5a5b1a32", "subject": "Fix Markdown conversion\n\nSaw half a season of The Office\n", "content": "* The flowchart's really helpful in visualizing how Varnish handles a\n request before asking the backend.\n* `default.vcl` comes with commented out subroutines which are worth\n a study.\n * I commented the hell out of them in this repo.\n* Test code with\n\n varnishd -C -f /etc/varnish/default.vcl\n\nPre-Flight\n----------\n\n # Install the repo \n rpm -ivh http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.noarch.rpm\n \n # Install Varnish \n yum -y install varnish \n \n # Make copy of config \n cp /etc/varnish/default.vcl{,.original}\n\nCan now start a varnish daemon with `varnishd` and specify the start\nparams [like the documentation asks you to\ndo](https://www.varnish-cache.org/docs/3.0/tutorial/starting_varnish.html).\nBut will use init daemons and sysconfig options on a RHEL box, which is\nneater.\n\nEdit `/etc/sysconfig/varnish`. Changed some default options:\n\n # Listen on all addresses, on the HTTP port \n VARNISH_LISTEN_ADDRESS= \n VARNISH_LISTEN_PORT=80 \n \n # Use a 250MB cache \n VARNISH_STORAGE_SIZE=250M \n       \n # Use malloc \n VARNISH_STORAGE=\"malloc,${VARNISH_STORAGE_SIZE}\"\n\nBoth \"file\" and \"malloc\" use disk and memory, [but in different\nways](https://www.varnish-software.com/static/book/Tuning.html#storage-backends).\n\nThis is the plan:\n\n World ---> Varnish ---> Nginx ---> Application Server \n            0.0.0.0:80 \n                         127.0.0.1:8080 \n                                    127.0.0.1:9090\n\nIn this case, the Nginx server is considered a \"backend server\" from\nwhich Varnish can request and then get data. I defined a simple one in\n`/etc/varnish/default.vcl`\n\n # Define a simple Nginx backend\n backend nginx_server {\n .host = \"localhost\";\n .port = \"8080\";\n }\n\nRestarted the varnish and nginx services, made sure they were listening\non the right ports.\n\n [root@example conf.d]# netstat -tunlp | grep 80 \n tcp  0   0 0.0.0.0:80        0.0.0.0:*     LISTEN   27090/varnishd \n tcp  0   0 127.0.0.1:8080    0.0.0.0:*     LISTEN   26861/nginx\n\nThe site should now work exactly as before. A few notes:\n\n* There's no caching taking place. Yet. That's where the VCL\n [DSL](http://en.wikipedia.org/wiki/Domain-specific_language)\n comes in.\n* Since I only have one server, I'm not interested in Varnish's\n load-balancing capabilities.\n\nMethods\n-------\n\n### vcl\\_recv\n\nThe entry point. I played around with the default subroutine by simply\nadding this to `default.vcl` and restarting Varnish:\n\n sub vcl_recv {\n # Check for a standard HTTP verb. If none used, bark.\n if (req.request != \"GET\") {\n error 400 \"I don't understand what you want me to do.\";\n }\n }\n\nAfter that, a simple `curl -X POST nikhil.io` yielded:\n\n \n \n \n \n *400 I don't understand what you want me to do.*\n \n \n

Error 400 I don't understand what you want me to do.

\n

I don't understand what you want me to do.

\n

Guru Meditation:

\n

XID: 2033234310

\n
\n

Varnish cache server

\n \n \n\nNice.\n\n### vcl\\_hash\n\nVarnish uses a key-value memory map. This subroutine defines how the key\nis generated. By default, it uses (URL or IP) + hostname.\n\n### vcl\\_pipe and vcl\\_pass\n\nCalled when `return(pipe)` or `return(pass)` are... returned from\n`vcl_recv`.\n\nIn pipe mode is the simplest \"Varnish-bypass\" mode, where it\nshort-circuits the connection between the client and the backend. No\ncaching, no logging. Varnish does nothing while client speaks to backend\n(still through Varnish.)\n\nIn pass mode, Varnish can look at (and manipulate) request and response\ndata\n\n### vcl\\_fetch\n\n* A full restart wipes the cache: neither \"file\" nor \"malloc\"\n are persistent.\n* You can see how Varnish translates the VCL into C code by:\n\n`   varnishd -C -f /etc/varnish/default.vcl`\n\n* Here's a useful [list of\n actions](https://www.varnish-cache.org/docs/3.0/tutorial/vcl.html#actions).\n" }, { "authorEmail": "mail@nikhil.io", "authorName": "Nikhil Anand", "date": "2015-12-21T02:30:47Z", "id": "3f2c54b1d767218fcb4855fbac306b015afaf551", "shortId": "3f2c54b1", "subject": "Incremental\n", "content": "- The flowchart's really helpful in visualizing how Varnish handles a\n request before asking the backend.\n- `default.vcl` comes with commented out subroutines which are worth\n a study.\n - I commented the hell out of them in this repo.\n- Test code with\n\n`   varnishd -C -f /etc/varnish/default.vcl`\n\nPre-Flight\n----------\n\n`   # Install the repo` \n`   rpm -ivh `[`http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.noarch.rpm`](http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.noarch.rpm) \n`   ` \n`   # Install Varnish` \n`   yum -y install varnish` \n`   ` \n`   # Make copy of config` \n`   cp /etc/varnish/default.vcl{,.original}`\n\nCan now start a varnish daemon with `varnishd` and specify the start\nparams [like the documentation asks you to\ndo](https://www.varnish-cache.org/docs/3.0/tutorial/starting_varnish.html).\nBut will use init daemons and sysconfig options on a RHEL box, which is\nneater.\n\nEdit `/etc/sysconfig/varnish`. Changed some default options:\n\n`   # Listen on all addresses, on the HTTP port` \n`   VARNISH_LISTEN_ADDRESS=` \n`   VARNISH_LISTEN_PORT=80` \n` ` \n`   # Use a 250MB cache` \n`   VARNISH_STORAGE_SIZE=250M` \n`        ` \n`   # Use malloc` \n`   VARNISH_STORAGE=\"malloc,${VARNISH_STORAGE_SIZE}\"`\n\nBoth \"file\" and \"malloc\" use disk and memory, [but in different\nways](https://www.varnish-software.com/static/book/Tuning.html#storage-backends).\n\nThis is the architecture:\n\n`   World ---> Varnish ---> Nginx ---> Application Server` \n`              0.0.0.0:80` \n`                           127.0.0.1:8080` \n`                                      127.0.0.1:9090`\n\nIn this case, the Nginx server is considered a \"backend server\" from\nwhich Varnish can request and then get data. I defined a simple one in\n`/etc/varnish/default.vcl`\n\n # Define a simple Nginx backend\n backend nginx_server {\n .host = \"localhost\";\n .port = \"8080\";\n }\n\nRestarted the varnish and nginx services, made sure they were listening\non the right ports.\n\n`   [root@nikhil conf.d]# netstat -tunlp | grep 80` \n`   tcp  0   0 0.0.0.0:80        0.0.0.0:*     LISTEN   27090/varnishd` \n`   tcp  0   0 127.0.0.1:8080    0.0.0.0:*     LISTEN   26861/nginx`\n\nThe site should now work exactly as before. A few notes:\n\n- There's no caching taking place. Yet. That's where the VCL\n [DSL](http://en.wikipedia.org/wiki/Domain-specific_language)\n comes in.\n- Since I only have one server, I'm not interested in Varnish's\n load-balancing capabilities.\n\nMethods\n-------\n\n### vcl\\_recv\n\nThe entry point. I played around with the default subroutine by simply\nadding this to `default.vcl` and restarting Varnish:\n\n sub vcl_recv {\n # Check for a standard HTTP verb. If none used, bark.\n if (req.request != \"GET\") {\n error 400 \"I don't understand what you want me to do.\";\n }\n }\n\nAfter that, a simple `curl -X POST nikhil.io` yielded:\n\n \n \n \n \n '''400 I don't understand what you want me to do.'''\n \n \n

Error 400 I don't understand what you want me to do.

\n

I don't understand what you want me to do.

\n

Guru Meditation:

\n

XID: 2033234310

\n
\n

Varnish cache server

\n \n \n\nNice.\n\n### vcl\\_hash\n\nVarnish uses a key-value memory map. This subroutine defines how the key\nis generated. By default, it uses (URL or IP) + hostname.\n\n### vcl\\_pipe and vcl\\_pass\n\nCalled when `return(pipe)` or `return(pass)` are... returned from\n`vcl_recv`.\n\nIn pipe mode is the simplest \"Varnish-bypass\" mode, where it\nshort-circuits the connection between the client and the backend. No\ncaching, no logging. Varnish does nothing while client speaks to backend\n(still through Varnish.)\n\nIn pass mode, Varnish can look at (and manipulate) request and response\ndata\n\n### vcl\\_fetch\n\n- A full restart wipes the cache: neither \"file\" nor \"malloc\"\n are persistent.\n- You can see how Varnish translates the VCL into C code by:\n\n`   varnishd -C -f /etc/varnish/default.vcl`\n\n- Here's a useful [list of\n actions](https://www.varnish-cache.org/docs/3.0/tutorial/vcl.html#actions).\n" }, { "authorEmail": "mail@nikhil.io", "authorName": "Nikhil Anand", "date": "2015-12-20T19:56:55Z", "id": "3604cc2f95a86dd34e52612f995322e133866e80", "shortId": "3604cc2f", "subject": "Varnish : v5", "content": "- The flowchart's really helpful in visualizing how Varnish handles a\n request before asking the backend.\n- `default.vcl` comes with commented out subroutines which are worth\n a study.\n - I commented the hell out of them in this repo.\n- Test code with\n\n`   varnishd -C -f /etc/varnish/default.vcl`\n\nPre-Flight\n----------\n\n`   # Install the repo` \n`   rpm -ivh `[`http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.noarch.rpm`](http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.noarch.rpm) \n` ` \n`   # Install Varnish` \n`   yum -y install varnish` \n` ` \n`   # Make copy of config` \n`   cp /etc/varnish/default.vcl{,.original}`\n\nCan now start a varnish daemon with `varnishd` and specify the start\nparams [like the documentation asks you to\ndo](https://www.varnish-cache.org/docs/3.0/tutorial/starting_varnish.html).\nBut will use init daemons and sysconfig options on a RHEL box, which is\nneater.\n\nEdit `/etc/sysconfig/varnish`. Changed some default options:\n\n`   # Listen on all addresses, on the HTTP port` \n`   VARNISH_LISTEN_ADDRESS=` \n`   VARNISH_LISTEN_PORT=80` \n` ` \n`   # Use a 250MB cache` \n`   VARNISH_STORAGE_SIZE=250M` \n`        ` \n`   # Use malloc` \n`   VARNISH_STORAGE=\"malloc,${VARNISH_STORAGE_SIZE}\"`\n\nBoth \"file\" and \"malloc\" use disk and memory, [but in different\nways](https://www.varnish-software.com/static/book/Tuning.html#storage-backends).\n\nThis is the architecture:\n\n`   World ---> Varnish ---> Nginx ---> Application Server` \n`              0.0.0.0:80` \n`                           127.0.0.1:8080` \n`                                      127.0.0.1:9090`\n\nIn this case, the Nginx server is considered a \"backend server\" from\nwhich Varnish can request and then get data. I defined a simple one in\n`/etc/varnish/default.vcl`\n\n # Define a simple Nginx backend\n backend nginx_server {\n .host = \"localhost\";\n .port = \"8080\";\n }\n\nRestarted the varnish and nginx services, made sure they were listening\non the right ports.\n\n`   [root@nikhil conf.d]# netstat -tunlp | grep 80` \n`   tcp  0   0 0.0.0.0:80        0.0.0.0:*     LISTEN   27090/varnishd` \n`   tcp  0   0 127.0.0.1:8080    0.0.0.0:*     LISTEN   26861/nginx`\n\nThe site should now work exactly as before. A few notes:\n\n- There's no caching taking place. Yet. That's where the VCL\n [DSL](http://en.wikipedia.org/wiki/Domain-specific_language)\n comes in.\n- Since I only have one server, I'm not interested in Varnish's\n load-balancing capabilities.\n\nMethods\n-------\n\n### vcl\\_recv\n\nThe entry point. I played around with the default subroutine by simply\nadding this to `default.vcl` and restarting Varnish:\n\n sub vcl_recv {\n # Check for a standard HTTP verb. If none used, bark.\n if (req.request != \"GET\") {\n error 400 \"I don't understand what you want me to do.\";\n }\n }\n\nAfter that, a simple `curl -X POST nikhil.io` yielded:\n\n \n \n \n \n '''400 I don't understand what you want me to do.'''\n \n \n

Error 400 I don't understand what you want me to do.

\n

I don't understand what you want me to do.

\n

Guru Meditation:

\n

XID: 2033234310

\n
\n

Varnish cache server

\n \n \n\nNice.\n\n### vcl\\_hash\n\nVarnish uses a key-value memory map. This subroutine defines how the key\nis generated. By default, it uses (URL or IP) + hostname.\n\n### vcl\\_pipe and vcl\\_pass\n\nCalled when `return(pipe)` or `return(pass)` are... returned from\n`vcl_recv`.\n\nIn pipe mode is the simplest \"Varnish-bypass\" mode, where it\nshort-circuits the connection between the client and the backend. No\ncaching, no logging. Varnish does nothing while client speaks to backend\n(still through Varnish.)\n\nIn pass mode, Varnish can look at (and manipulate) request and response\ndata\n\n### vcl\\_fetch\n\n- A full restart wipes the cache: neither \"file\" nor \"malloc\"\n are persistent.\n- You can see how Varnish translates the VCL into C code by:\n\n`   varnishd -C -f /etc/varnish/default.vcl`\n\n- Here's a useful [list of\n actions](https://www.varnish-cache.org/docs/3.0/tutorial/vcl.html#actions).\n\n[Category: Nikhil's Notes](Category:_Nikhil's_Notes \"wikilink\")\n[Category: Linux](Category:_Linux \"wikilink\")\n" }, { "authorEmail": "mail@nikhil.io", "authorName": "Nikhil Anand", "date": "2015-12-20T19:56:55Z", "id": "3fab273f0c36353fdc7de601c3451b9c82c90188", "shortId": "3fab273f", "subject": "Varnish : v4", "content": "- The flowchart's really helpful in visualizing how Varnish handles a\n request before asking the backend.\n- `default.vcl` comes with commented out subroutines which are worth\n a study.\n - I commented the hell out of them in this repo.\n- Test code with\n\n`   varnishd -C -f /etc/varnish/default.vcl`\n\nPre-Flight\n----------\n\n`   # Install the repo` \n`   rpm -ivh `[`http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.noarch.rpm`](http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.noarch.rpm) \n` ` \n`   # Install Varnish` \n`   yum -y install varnish` \n` ` \n`   # Make copy of config` \n`   cp /etc/varnish/default.vcl{,.original}`\n\nCan now start a varnish daemon with `varnishd` and specify the start\nparams [like the documentation asks you to\ndo](https://www.varnish-cache.org/docs/3.0/tutorial/starting_varnish.html).\nBut will use init daemons and sysconfig options on a RHEL box, which is\nneater.\n\nEdit `/etc/sysconfig/varnish`. Changed some default options:\n\n`   # Listen on all addresses, on the HTTP port` \n`   VARNISH_LISTEN_ADDRESS=` \n`   VARNISH_LISTEN_PORT=80` \n` ` \n`   # Use a 250MB cache` \n`   VARNISH_STORAGE_SIZE=250M` \n`        ` \n`   # Use malloc` \n`   VARNISH_STORAGE=\"malloc,${VARNISH_STORAGE_SIZE}\"`\n\nBoth \"file\" and \"malloc\" use disk and memory, [but in different\nways](https://www.varnish-software.com/static/book/Tuning.html#storage-backends).\n\nThis is the architecture:\n\n`   World ---> Varnish ---> Nginx ---> Application Server` \n`              0.0.0.0:80` \n`                           127.0.0.1:8080` \n`                                      127.0.0.1:9090`\n\nIn this case, the Nginx server is considered a \"backend server\" from\nwhich Varnish can request and then get data. I defined a simple one in\n`/etc/varnish/default.vcl`\n\n # Define a simple Nginx backend\n backend nginx_server {\n .host = \"localhost\";\n .port = \"8080\";\n }\n\nRestarted the varnish and nginx services, made sure they were listening\non the right ports.\n\n`   [root@nikhil conf.d]# netstat -tunlp | grep 80` \n`   tcp  0   0 0.0.0.0:80        0.0.0.0:*     LISTEN   27090/varnishd` \n`   tcp  0   0 127.0.0.1:8080    0.0.0.0:*     LISTEN   26861/nginx`\n\nThe site should now work exactly as before. A few notes:\n\n- There's no caching taking place. Yet. That's where the VCL\n [DSL](http://en.wikipedia.org/wiki/Domain-specific_language)\n comes in.\n- Since I only have one server, I'm not interested in Varnish's\n load-balancing capabilities.\n\nMethods\n-------\n\n### vcl\\_recv\n\nThe entry point. I played around with the default subroutine by simply\nadding this to `default.vcl` and restarting Varnish:\n\n sub vcl_recv {\n # Check for a standard HTTP verb. If none used, bark.\n if (req.request != \"GET\") {\n error 400 \"I don't understand what you want me to do.\";\n }\n }\n\nAfter that, a simple `curl -X POST nikhil.io` yielded:\n\n\n\n\n\n`       '''`\n\n\n400 I don't understand what you want me to do.\n\n\n'''\n\n\n\n

\nError 400 I don't understand what you want me to do.\n\n

\nI don't understand what you want me to do.\n\n

\nGuru Meditation:\n\n

\nXID: 2033234310\n\n
\nVarnish cache server\n\n\n\nNice.\n\n### vcl\\_hash\n\nVarnish uses a key-value memory map. This subroutine defines how the key\nis generated. By default, it uses (URL or IP) + hostname.\n\n### vcl\\_pipe and vcl\\_pass\n\nCalled when `return(pipe)` or `return(pass)` are... returned from\n`vcl_recv`.\n\nIn pipe mode is the simplest \"Varnish-bypass\" mode, where it\nshort-circuits the connection between the client and the backend. No\ncaching, no logging. Varnish does nothing while client speaks to backend\n(still through Varnish.)\n\nIn pass mode, Varnish can look at (and manipulate) request and response\ndata\n\n### vcl\\_fetch\n\n- A full restart wipes the cache: neither \"file\" nor \"malloc\"\n are persistent.\n- You can see how Varnish translates the VCL into C code by:\n\n`   varnishd -C -f /etc/varnish/default.vcl`\n\n- Here's a useful [list of\n actions](https://www.varnish-cache.org/docs/3.0/tutorial/vcl.html#actions).\n\n[Category: Nikhil's Notes](Category:_Nikhil's_Notes \"wikilink\")\n[Category: Linux](Category:_Linux \"wikilink\")\n" }, { "authorEmail": "mail@nikhil.io", "authorName": "Nikhil Anand", "date": "2015-12-20T19:56:55Z", "id": "fe28f6afd1132b7ceb0b5ca10b99cb1fc04d4853", "shortId": "fe28f6af", "subject": "Varnish : v3", "content": "- The flowchart's really helpful in visualizing how Varnish handles a\n request before asking the backend.\n- `default.vcl` comes with commented out subroutines which are worth\n a study.\n - I commented the hell out of them in this repo.\n- Test code with\n\n`   varnishd -C -f /etc/varnish/default.vcl`\n\nPre-Flight\n----------\n\n`   # Install the repo` \n`   rpm -ivh `[`http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.noarch.rpm`](http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.noarch.rpm) \n` ` \n`   # Install Varnish` \n`   yum -y install varnish` \n` ` \n`   # Make copy of config` \n`   cp /etc/varnish/default.vcl{,.original}`\n\nCan now start a varnish daemon with `varnishd` and specify the start\nparams [like the documentation asks you to\ndo](https://www.varnish-cache.org/docs/3.0/tutorial/starting_varnish.html).\nBut will use init daemons and sysconfig options on a RHEL box, which is\nneater.\n\nEdit `/etc/sysconfig/varnish`. Changed some default options:\n\n`   # Listen on all addresses, on the HTTP port` \n`   VARNISH_LISTEN_ADDRESS=` \n`   VARNISH_LISTEN_PORT=80` \n` ` \n`   # Use a 250MB cache` \n`   VARNISH_STORAGE_SIZE=250M` \n`        ` \n`   # Use malloc` \n`   VARNISH_STORAGE=\"malloc,${VARNISH_STORAGE_SIZE}\"`\n\nBoth \"file\" and \"malloc\" use disk and memory, [but in different\nways](https://www.varnish-software.com/static/book/Tuning.html#storage-backends).\n\nThis is the architecture:\n\n`   World ---> Varnish ---> Nginx ---> Application Server` \n`              0.0.0.0:80` \n`                           127.0.0.1:8080` \n`                                      127.0.0.1:9090`\n\nIn this case, the Nginx server is considered a \"backend server\" from\nwhich Varnish can request and then get data. I defined a simple one in\n`/etc/varnish/default.vcl`\n\n # Define a simple Nginx backend\n backend nginx_server {\n .host = \"localhost\";\n .port = \"8080\";\n }\n\nRestarted the varnish and nginx services, made sure they were listening\non the right ports.\n\n`   [root@nikhil conf.d]# netstat -tunlp | grep 80` \n`   tcp  0   0 0.0.0.0:80        0.0.0.0:*     LISTEN   27090/varnishd` \n`   tcp  0   0 127.0.0.1:8080    0.0.0.0:*     LISTEN   26861/nginx`\n\nThe site should now work exactly as before. A few notes:\n\n- There's no caching taking place. Yet. That's where the VCL\n [DSL](http://en.wikipedia.org/wiki/Domain-specific_language)\n comes in.\n- Since I only have one server, I'm not interested in Varnish's\n load-balancing capabilities.\n\nMethods\n-------\n\n### vcl\\_recv\n\nThe entry point. I played around with the default subroutine by simply\nadding this to `default.vcl` and restarting Varnish:\n\n sub vcl_recv {\n # Check for a standard HTTP verb. If none used, bark.\n if (req.request != \"GET\") {\n error 400 \"I don't understand what you want me to do.\";\n }\n }\n\nAfter that, a simple `curl -X POST nikhil.io` yielded:\n\n \n \n \n \n '''400 I don't understand what you want me to do.'''\n \n \n

Error 400 I don't understand what you want me to do.

\n

I don't understand what you want me to do.

\n

Guru Meditation:

\n

XID: 2033234310

\n
\n

Varnish cache server

\n \n \n\nNice.\n\n### vcl\\_hash\n\nVarnish uses a key-value memory map. This subroutine defines how the key\nis generated. By default, it uses (URL or IP) + hostname.\n\n### vcl\\_pipe and vcl\\_pass\n\nCalled when `return(pipe)` or `return(pass)` are... returned from\n`vcl_recv`.\n\nIn pipe mode is the simplest \"Varnish-bypass\" mode, where it\nshort-circuits the connection between the client and the backend. No\ncaching, no logging. Varnish does nothing while client speaks to backend\n(still through Varnish.)\n\nIn pass mode, Varnish can look at (and manipulate) request and response\ndata\n\n### vcl\\_fetch\n\n- A full restart wipes the cache: neither \"file\" nor \"malloc\"\n are persistent.\n- You can see how Varnish translates the VCL into C code by:\n\n`   varnishd -C -f /etc/varnish/default.vcl`\n\n- Here's a useful [list of\n actions](https://www.varnish-cache.org/docs/3.0/tutorial/vcl.html#actions).\n\n[Category: Nikhil's Notes](Category:_Nikhil's_Notes \"wikilink\")\n[Category: Linux](Category:_Linux \"wikilink\")\n" }, { "authorEmail": "mail@nikhil.io", "authorName": "Nikhil Anand", "date": "2015-12-20T19:56:55Z", "id": "0d7022625cf99a11141458ccecbc95b7caa6e34b", "shortId": "0d702262", "subject": "Varnish : v2", "content": "- The flowchart's really helpful in visualizing how Varnish handles a\n request before asking the backend.\n- `default.vcl` comes with commented out subroutines which are worth\n a study.\n - I commented the hell out of them in this repo.\n- Test code with\n\n`   varnishd -C -f /etc/varnish/default.vcl`\n\nPre-Flight\n----------\n\n`   # Install the repo` \n`   rpm -ivh `[`http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.noarch.rpm`](http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.noarch.rpm)\n\n`   # Install Varnish` \n`   yum -y install varnish`\n\n`   # Make copy of config` \n`   cp /etc/varnish/default.vcl{,.original}`\n\nCan now start a varnish daemon with `varnishd` and specify the start\nparams [like the documentation asks you to\ndo](https://www.varnish-cache.org/docs/3.0/tutorial/starting_varnish.html).\nBut will use init daemons and sysconfig options on a RHEL box, which is\nneater.\n\nEdit `/etc/sysconfig/varnish`. Changed some default options:\n\n`   # Listen on all addresses, on the HTTP port` \n`   VARNISH_LISTEN_ADDRESS=` \n`   VARNISH_LISTEN_PORT=80`\n\n`   # Use a 250MB cache` \n`   VARNISH_STORAGE_SIZE=250M` \n`       ` \n`   # Use malloc` \n`   VARNISH_STORAGE=\"malloc,${VARNISH_STORAGE_SIZE}\"`\n\nBoth \"file\" and \"malloc\" use disk and memory, [but in different\nways](https://www.varnish-software.com/static/book/Tuning.html#storage-backends).\n\nThis is the architecture:\n\n`   World ---> Varnish ---> Nginx ---> Application Server` \n`              0.0.0.0:80` \n`                           127.0.0.1:8080` \n`                                      127.0.0.1:9090`\n\nIn this case, the Nginx server is considered a \"backend server\" from\nwhich Varnish can request and then get data. I defined a simple one in\n`/etc/varnish/default.vcl`\n\n # Define a simple Nginx backend\n backend nginx_server {\n .host = \"localhost\";\n .port = \"8080\";\n }\n\nRestarted the varnish and nginx services, made sure they were listening\non the right ports.\n\n`   [root@nikhil conf.d]# netstat -tunlp | grep 80` \n`   tcp  0   0 0.0.0.0:80        0.0.0.0:*     LISTEN   27090/varnishd` \n`   tcp  0   0 127.0.0.1:8080    0.0.0.0:*     LISTEN   26861/nginx`\n\nThe site should now work exactly as before. A few notes:\n\n- There's no caching taking place. Yet. That's where the VCL\n [DSL](http://en.wikipedia.org/wiki/Domain-specific_language)\n comes in.\n- Since I only have one server, I'm not interested in Varnish's\n load-balancing capabilities.\n\nMethods\n-------\n\n### vcl\\_recv\n\nThe entry point. I played around with the default subroutine by simply\nadding this to `default.vcl` and restarting Varnish:\n\n sub vcl_recv {\n # Check for a standard HTTP verb. If none used, bark.\n if (req.request != \"GET\") {\n error 400 \"I don't understand what you want me to do.\";\n }\n }\n\nAfter that, a simple `curl -X POST nikhil.io` yielded:\n\n \n \n \n \n '''400 I don't understand what you want me to do.'''\n \n \n

Error 400 I don't understand what you want me to do.

\n

I don't understand what you want me to do.

\n

Guru Meditation:

\n

XID: 2033234310

\n
\n

Varnish cache server

\n \n \n\nNice.\n\n### vcl\\_hash\n\nVarnish uses a key-value memory map. This subroutine defines how the key\nis generated. By default, it uses (URL or IP) + hostname.\n\n### vcl\\_pipe and vcl\\_pass\n\nCalled when `return(pipe)` or `return(pass)` are... returned from\n`vcl_recv`.\n\nIn pipe mode is the simplest \"Varnish-bypass\" mode, where it\nshort-circuits the connection between the client and the backend. No\ncaching, no logging. Varnish does nothing while client speaks to backend\n(still through Varnish.)\n\nIn pass mode, Varnish can look at (and manipulate) request and response\ndata\n\n### vcl\\_fetch\n\n- A full restart wipes the cache: neither \"file\" nor \"malloc\"\n are persistent.\n- You can see how Varnish translates the VCL into C code by:\n\n`   varnishd -C -f /etc/varnish/default.vcl`\n\n- Here's a useful [list of\n actions](https://www.varnish-cache.org/docs/3.0/tutorial/vcl.html#actions).\n\n[Category: Nikhil's Notes](Category:_Nikhil's_Notes \"wikilink\")\n[Category: Linux](Category:_Linux \"wikilink\")\n" }, { "authorEmail": "mail@nikhil.io", "authorName": "Nikhil Anand", "date": "2015-12-20T19:56:55Z", "id": "3b3f838fa690f0d44e014767aa2f7ce64fe75f94", "shortId": "3b3f838f", "subject": "Varnish : v6", "content": "- The flowchart's really helpful in visualizing how Varnish handles a\n request before asking the backend.\n- `default.vcl` comes with commented out subroutines which are worth\n a study.\n - I commented the hell out of them in this repo.\n- Test code with\n\n`   varnishd -C -f /etc/varnish/default.vcl`\n\nPre-Flight\n----------\n\n`   # Install the repo` \n`   rpm -ivh `[`http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.noarch.rpm`](http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.noarch.rpm) \n`   ` \n`   # Install Varnish` \n`   yum -y install varnish` \n`   ` \n`   # Make copy of config` \n`   cp /etc/varnish/default.vcl{,.original}`\n\nCan now start a varnish daemon with `varnishd` and specify the start\nparams [like the documentation asks you to\ndo](https://www.varnish-cache.org/docs/3.0/tutorial/starting_varnish.html).\nBut will use init daemons and sysconfig options on a RHEL box, which is\nneater.\n\nEdit `/etc/sysconfig/varnish`. Changed some default options:\n\n`   # Listen on all addresses, on the HTTP port` \n`   VARNISH_LISTEN_ADDRESS=` \n`   VARNISH_LISTEN_PORT=80` \n` ` \n`   # Use a 250MB cache` \n`   VARNISH_STORAGE_SIZE=250M` \n`        ` \n`   # Use malloc` \n`   VARNISH_STORAGE=\"malloc,${VARNISH_STORAGE_SIZE}\"`\n\nBoth \"file\" and \"malloc\" use disk and memory, [but in different\nways](https://www.varnish-software.com/static/book/Tuning.html#storage-backends).\n\nThis is the architecture:\n\n`   World ---> Varnish ---> Nginx ---> Application Server` \n`              0.0.0.0:80` \n`                           127.0.0.1:8080` \n`                                      127.0.0.1:9090`\n\nIn this case, the Nginx server is considered a \"backend server\" from\nwhich Varnish can request and then get data. I defined a simple one in\n`/etc/varnish/default.vcl`\n\n # Define a simple Nginx backend\n backend nginx_server {\n .host = \"localhost\";\n .port = \"8080\";\n }\n\nRestarted the varnish and nginx services, made sure they were listening\non the right ports.\n\n`   [root@nikhil conf.d]# netstat -tunlp | grep 80` \n`   tcp  0   0 0.0.0.0:80        0.0.0.0:*     LISTEN   27090/varnishd` \n`   tcp  0   0 127.0.0.1:8080    0.0.0.0:*     LISTEN   26861/nginx`\n\nThe site should now work exactly as before. A few notes:\n\n- There's no caching taking place. Yet. That's where the VCL\n [DSL](http://en.wikipedia.org/wiki/Domain-specific_language)\n comes in.\n- Since I only have one server, I'm not interested in Varnish's\n load-balancing capabilities.\n\nMethods\n-------\n\n### vcl\\_recv\n\nThe entry point. I played around with the default subroutine by simply\nadding this to `default.vcl` and restarting Varnish:\n\n sub vcl_recv {\n # Check for a standard HTTP verb. If none used, bark.\n if (req.request != \"GET\") {\n error 400 \"I don't understand what you want me to do.\";\n }\n }\n\nAfter that, a simple `curl -X POST nikhil.io` yielded:\n\n \n \n \n \n '''400 I don't understand what you want me to do.'''\n \n \n

Error 400 I don't understand what you want me to do.

\n

I don't understand what you want me to do.

\n

Guru Meditation:

\n

XID: 2033234310

\n
\n

Varnish cache server

\n \n \n\nNice.\n\n### vcl\\_hash\n\nVarnish uses a key-value memory map. This subroutine defines how the key\nis generated. By default, it uses (URL or IP) + hostname.\n\n### vcl\\_pipe and vcl\\_pass\n\nCalled when `return(pipe)` or `return(pass)` are... returned from\n`vcl_recv`.\n\nIn pipe mode is the simplest \"Varnish-bypass\" mode, where it\nshort-circuits the connection between the client and the backend. No\ncaching, no logging. Varnish does nothing while client speaks to backend\n(still through Varnish.)\n\nIn pass mode, Varnish can look at (and manipulate) request and response\ndata\n\n### vcl\\_fetch\n\n- A full restart wipes the cache: neither \"file\" nor \"malloc\"\n are persistent.\n- You can see how Varnish translates the VCL into C code by:\n\n`   varnishd -C -f /etc/varnish/default.vcl`\n\n- Here's a useful [list of\n actions](https://www.varnish-cache.org/docs/3.0/tutorial/vcl.html#actions).\n\n[Category: Nikhil's Notes](Category:_Nikhil's_Notes \"wikilink\")\n[Category: Linux](Category:_Linux \"wikilink\")\n" }, { "authorEmail": "mail@nikhil.io", "authorName": "Nikhil Anand", "date": "2015-12-20T19:56:54Z", "id": "cd957036b5e4d093b5cb09b0dc99d2d58d131dc9", "shortId": "cd957036", "subject": "Varnish : First Draft", "content": "`   # Install the repo` \n`   rpm -ivh `[`http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.noarch.rpm`](http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.noarch.rpm)\n\n`   # Install Varnish` \n`   yum -y install varnish`\n\n`   # Make copy of config` \n`   cp /etc/varnish/default.vcl{,.original}`\n\nCan now start a varnish daemon with `varnishd` and specify the start\nparams [like the documentation asks you to\ndo](https://www.varnish-cache.org/docs/3.0/tutorial/starting_varnish.html).\nBut will use init daemons and sysconfig options on a RHEL box, which is\nneater.\n\nEdit `/etc/sysconfig/varnish`. Changed some default options:\n\n`   # Listen on all addresses, on the HTTP port` \n`   VARNISH_LISTEN_ADDRESS=` \n`   VARNISH_LISTEN_PORT=80`\n\n`   # Use a 250MB cache` \n`   VARNISH_STORAGE_SIZE=250M` \n`   ` \n`   # Use malloc` \n`   VARNISH_STORAGE=\"malloc,${VARNISH_STORAGE_SIZE}\"`\n\nBoth \"file\" and \"malloc\" use disk and memory, [but in different\nways](https://www.varnish-software.com/static/book/Tuning.html#storage-backends).\n\nThis is the architecture:\n\n`   World ---> Varnish ---> Nginx ---> Application Server` \n`              0.0.0.0:80` \n`                           127.0.0.1:8080` \n`                                      127.0.0.1:9090`\n\nIn this case, the Nginx server is considered a \"backend server\" from\nwhich Varnish can request and then get data. I defined a simple one in\n`/etc/varnish/default.vcl`\n\n # Define a simple Nginx backend\n backend nginx_server {\n .host = \"localhost\";\n .port = \"8080\";\n }\n\nRestarted the varnish and nginx services, made sure they were listening\non the right ports.\n\n`   [root@nikhil conf.d]# netstat -tunlp | grep 80` \n`   tcp  0   0 0.0.0.0:80        0.0.0.0:*     LISTEN   27090/varnishd` \n`   tcp  0   0 127.0.0.1:8080    0.0.0.0:*     LISTEN   26861/nginx`\n\nThe site should now work exactly as before. A few notes:\n\n- There's no caching taking place. Yet. That's where the VCL\n [DSL](http://en.wikipedia.org/wiki/Domain-specific_language)\n comes in.\n- Since I only have one server, I'm not interested in Varnish's\n load-balancing capabilities.\n\nVCL Notes\n---------\n\n- The flowchart's really helpful in visualizing how Varnish handles a\n request before asking the backend.\n- `default.vcl` comes with commented out subroutines which are worth\n a study.\n - I commented the hell out of them in this repo.\n- Test code with\n\n`   varnishd -C -f /etc/varnish/default.vcl`\n\n### vcl\\_recv\n\nThe entry point. I played around with the default subroutine by simply\nadding this to `default.vcl` and restarting Varnish:\n\n sub vcl_recv {\n # Check for a standard HTTP verb. If none used, bark.\n if (req.request != \"GET\") {\n error 400 \"I don't understand what you want me to do.\";\n }\n }\n\nAfter that, a simple `curl -X POST nikhil.io` yielded:\n\n\n\n\n\n`       '''`\n\n\n400 I don't understand what you want me to do.\n\n\n'''\n\n\n\n

\nError 400 I don't understand what you want me to do.\n\n

\nI don't understand what you want me to do.\n\n

\nGuru Meditation:\n\n

\nXID: 2033234310\n\n
\nVarnish cache server\n\n\n\nNice.\n\n### vcl\\_hash\n\nVarnish uses a key-value memory map. This subroutine defines how the key\nis generated. By default, it uses (URL or IP) + hostname.\n\n### vcl\\_pipe and vcl\\_pass\n\nCalled when `return(pipe)` or `return(pass)` are... returned from\n`vcl_recv`.\n\nIn pipe mode is the simplest \"Varnish-bypass\" mode, where it\nshort-circuits the connection between the client and the backend. No\ncaching, no logging. Varnish does nothing while client speaks to backend\n(still through Varnish.)\n\nIn pass mode, Varnish can look at (and manipulate) request and response\ndata\n\n### vcl\\_fetch\n\n- A full restart wipes the cache: neither \"file\" nor \"malloc\"\n are persistent.\n- You can see how Varnish translates the VCL into C code by:\n\n`   varnishd -C -f /etc/varnish/default.vcl`\n\n- Here's a useful [list of\n actions](https://www.varnish-cache.org/docs/3.0/tutorial/vcl.html#actions).\n- \n\n[Category: Nikhil's Notes](Category:_Nikhil's_Notes \"wikilink\")\n[Category: Linux](Category:_Linux \"wikilink\")\n" } ], "sizeInBytes": 4486, "source": "* The flowchart's really helpful in visualizing how Varnish handles a\n request before asking the backend.\n* `default.vcl` comes with commented out subroutines which are worth\n a study.\n * I commented the hell out of them in this repo.\n* Test code with\n\n varnishd -C -f /etc/varnish/default.vcl\n\nPre-Flight\n----------\n\n # Install the repo \n rpm -ivh http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.noarch.rpm\n \n # Install Varnish \n yum -y install varnish \n \n # Make copy of config \n cp /etc/varnish/default.vcl{,.original}\n\nCan now start a varnish daemon with `varnishd` and specify the start\nparams [like the documentation asks you to\ndo](https://www.varnish-cache.org/docs/3.0/tutorial/starting_varnish.html).\nBut will use init daemons and sysconfig options on a RHEL box, which is\nneater.\n\nEdit `/etc/sysconfig/varnish`. Changed some default options:\n\n # Listen on all addresses, on the HTTP port \n VARNISH_LISTEN_ADDRESS= \n VARNISH_LISTEN_PORT=80 \n \n # Use a 250MB cache \n VARNISH_STORAGE_SIZE=250M \n       \n # Use malloc \n VARNISH_STORAGE=\"malloc,${VARNISH_STORAGE_SIZE}\"\n\nBoth \"file\" and \"malloc\" use disk and memory, [but in different\nways](https://www.varnish-software.com/static/book/Tuning.html#storage-backends).\n\nThis is the plan:\n\n World ---> Varnish ---> Nginx ---> Application Server \n            0.0.0.0:80 \n                         127.0.0.1:8080 \n                                    127.0.0.1:9090\n\nIn this case, the Nginx server is considered a \"backend server\" from\nwhich Varnish can request and then get data. I defined a simple one in\n`/etc/varnish/default.vcl`\n\n # Define a simple Nginx backend\n backend nginx_server {\n .host = \"localhost\";\n .port = \"8080\";\n }\n\nRestarted the varnish and nginx services, made sure they were listening\non the right ports.\n\n [root@example conf.d]# netstat -tunlp | grep 80 \n tcp  0   0 0.0.0.0:80        0.0.0.0:*     LISTEN   27090/varnishd \n tcp  0   0 127.0.0.1:8080    0.0.0.0:*     LISTEN   26861/nginx\n\nThe site should now work exactly as before. A few notes:\n\n* There's no caching taking place. Yet. That's where the VCL\n [DSL](http://en.wikipedia.org/wiki/Domain-specific_language)\n comes in.\n* Since I only have one server, I'm not interested in Varnish's\n load-balancing capabilities.\n\nMethods\n-------\n\n### vcl\\_recv\n\nThe entry point. I played around with the default subroutine by simply\nadding this to `default.vcl` and restarting Varnish:\n\n sub vcl_recv {\n # Check for a standard HTTP verb. If none used, bark.\n if (req.request != \"GET\") {\n error 400 \"I don't understand what you want me to do.\";\n }\n }\n\nAfter that, a simple `curl -X POST nikhil.io` yielded:\n\n \n \n \n \n *400 I don't understand what you want me to do.*\n \n \n

Error 400 I don't understand what you want me to do.

\n

I don't understand what you want me to do.

\n

Guru Meditation:

\n

XID: 2033234310

\n
\n

Varnish cache server

\n \n \n\nNice.\n\n### vcl\\_hash\n\nVarnish uses a key-value memory map. This subroutine defines how the key\nis generated. By default, it uses (URL or IP) + hostname.\n\n### vcl\\_pipe and vcl\\_pass\n\nCalled when `return(pipe)` or `return(pass)` are... returned from\n`vcl_recv`.\n\nIn pipe mode is the simplest \"Varnish-bypass\" mode, where it\nshort-circuits the connection between the client and the backend. No\ncaching, no logging. Varnish does nothing while client speaks to backend\n(still through Varnish.)\n\nIn pass mode, Varnish can look at (and manipulate) request and response\ndata\n\n### vcl\\_fetch\n\n* A full restart wipes the cache: neither \"file\" nor \"malloc\"\n are persistent.\n* You can see how Varnish translates the VCL into C code by:\n\n`   varnishd -C -f /etc/varnish/default.vcl`\n\n* Here's a useful [list of\n actions](https://www.varnish-cache.org/docs/3.0/tutorial/vcl.html#actions).\n", "title": "Varnish", "untracked": false, "uri": "/Varnish" }