Skip to content

Commit 1be82b9

Browse files
authored
Merge pull request #2429 from gquintard/master
varnish: introduce new env variables
2 parents ad299b2 + 41dbe6c commit 1be82b9

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

varnish/content.md

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,26 @@ Varnish is an HTTP accelerator designed for content-heavy dynamic web sites as w
1010

1111
## Basic usage
1212

13-
Create a `default.vcl` file:
14-
15-
```vcl
16-
# specify the VCL syntax version to use
17-
vcl 4.1;
18-
19-
# import vmod_dynamic for better backend name resolution
20-
import dynamic;
21-
22-
# we won't use any static backend, but Varnish still need a default one
23-
backend default none;
24-
25-
# set up a dynamic director
26-
# for more info, see https://github.com/nigoroll/libvmod-dynamic/blob/master/src/vmod_dynamic.vcc
27-
sub vcl_init {
28-
new d = dynamic.director(port = "80");
29-
}
30-
31-
sub vcl_recv {
32-
# force the host header to match the backend (not all backends need it,
33-
# but example.com does)
34-
set req.http.host = "example.com";
35-
# set the backend
36-
set req.backend_hint = d.backend("example.com");
37-
}
13+
### Using `VARNISH_BACKEND_HOST` and `VARNISH_BACKEND_PORT`
14+
15+
You just need to know where your backend (the server that Varnish will accelerate) is:
16+
17+
```console
18+
# we define VARNISH_BACKEND_HOST/VARNISH_BACKEND_PORT
19+
# our workdir has to be mounted as tmpfs to avoid disk I/O,
20+
# and we'll use port 8080 to talk to our container (internally listening on 80)
21+
$ docker run \
22+
-e VARNISH_BACKEND_HOST=example.com -e VARNISH_BACKEND_PORT=80 \
23+
--tmpfs /var/lib/varnish/varnishd:exec \
24+
-p 8080:80 \
25+
%%IMAGE%%
3826
```
3927

40-
Then run:
28+
From there, you can visit `localhost:8080` in your browser and see the example.com homepage.
29+
30+
### Using a VCL file
31+
32+
If you already have a VCL file, you can directly mount it as `/etc/varnish/default.vcl`:
4133

4234
```console
4335
# we need the configuration file at /etc/varnish/default.vcl,
@@ -50,9 +42,7 @@ $ docker run \
5042
%%IMAGE%%
5143
```
5244

53-
From there, you can visit `localhost:8080` in your browser and see the example.com homepage.
54-
55-
Alternatively, a simple `Dockerfile` can be used to generate a new image that includes the necessary `default.vcl` (which is a much cleaner solution than the bind mount above):
45+
Alternatively, a simple `Dockerfile` can be used to generate a new image that includes the necessary `default.vcl`:
5646

5747
```dockerfile
5848
FROM %%IMAGE%%

0 commit comments

Comments
 (0)