Merge pull request #2429 from gquintard/master
varnish: introduce new env variables
This commit is contained in:
commit
1be82b9838
|
|
@ -10,34 +10,26 @@ Varnish is an HTTP accelerator designed for content-heavy dynamic web sites as w
|
||||||
|
|
||||||
## Basic usage
|
## Basic usage
|
||||||
|
|
||||||
Create a `default.vcl` file:
|
### Using `VARNISH_BACKEND_HOST` and `VARNISH_BACKEND_PORT`
|
||||||
|
|
||||||
```vcl
|
You just need to know where your backend (the server that Varnish will accelerate) is:
|
||||||
# specify the VCL syntax version to use
|
|
||||||
vcl 4.1;
|
|
||||||
|
|
||||||
# import vmod_dynamic for better backend name resolution
|
```console
|
||||||
import dynamic;
|
# we define VARNISH_BACKEND_HOST/VARNISH_BACKEND_PORT
|
||||||
|
# our workdir has to be mounted as tmpfs to avoid disk I/O,
|
||||||
# we won't use any static backend, but Varnish still need a default one
|
# and we'll use port 8080 to talk to our container (internally listening on 80)
|
||||||
backend default none;
|
$ docker run \
|
||||||
|
-e VARNISH_BACKEND_HOST=example.com -e VARNISH_BACKEND_PORT=80 \
|
||||||
# set up a dynamic director
|
--tmpfs /var/lib/varnish/varnishd:exec \
|
||||||
# for more info, see https://github.com/nigoroll/libvmod-dynamic/blob/master/src/vmod_dynamic.vcc
|
-p 8080:80 \
|
||||||
sub vcl_init {
|
%%IMAGE%%
|
||||||
new d = dynamic.director(port = "80");
|
|
||||||
}
|
|
||||||
|
|
||||||
sub vcl_recv {
|
|
||||||
# force the host header to match the backend (not all backends need it,
|
|
||||||
# but example.com does)
|
|
||||||
set req.http.host = "example.com";
|
|
||||||
# set the backend
|
|
||||||
set req.backend_hint = d.backend("example.com");
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Then run:
|
From there, you can visit `localhost:8080` in your browser and see the example.com homepage.
|
||||||
|
|
||||||
|
### Using a VCL file
|
||||||
|
|
||||||
|
If you already have a VCL file, you can directly mount it as `/etc/varnish/default.vcl`:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
# we need the configuration file at /etc/varnish/default.vcl,
|
# we need the configuration file at /etc/varnish/default.vcl,
|
||||||
|
|
@ -50,9 +42,7 @@ $ docker run \
|
||||||
%%IMAGE%%
|
%%IMAGE%%
|
||||||
```
|
```
|
||||||
|
|
||||||
From there, you can visit `localhost:8080` in your browser and see the example.com homepage.
|
Alternatively, a simple `Dockerfile` can be used to generate a new image that includes the necessary `default.vcl`:
|
||||||
|
|
||||||
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):
|
|
||||||
|
|
||||||
```dockerfile
|
```dockerfile
|
||||||
FROM %%IMAGE%%
|
FROM %%IMAGE%%
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue