[varnish] Use Varnish 4.1, redirect to HTTPS
This commit is contained in:
parent
9b403a625f
commit
a3a2afdc59
2 changed files with 16 additions and 6 deletions
|
|
@ -1,11 +1,14 @@
|
||||||
FROM centos:7
|
FROM centos:7
|
||||||
MAINTAINER Vincent Ambo <hej@tazj.in>
|
MAINTAINER Vincent Ambo <hej@tazj.in>
|
||||||
|
|
||||||
EXPOSE 6081 6082
|
EXPOSE 6081 6082 6083
|
||||||
|
|
||||||
RUN yum install -y epel-release && yum install -y varnish
|
RUN yum install -y epel-release && \
|
||||||
|
rpm --nosignature -i https://repo.varnish-cache.org/redhat/varnish-4.1.el7.rpm && \
|
||||||
|
yum install -y varnish
|
||||||
|
|
||||||
ADD default.vcl /etc/varnish/default.vcl
|
ADD default.vcl /etc/varnish/default.vcl
|
||||||
|
|
||||||
CMD ulimit -n 131072 && \
|
CMD ulimit -n 131072 && \
|
||||||
/usr/sbin/varnishd -F -f /etc/varnish/default.vcl -a :6081 -T :6082 -t 120
|
/usr/sbin/varnishd -F -f /etc/varnish/default.vcl \
|
||||||
|
-a :6081 -T :6082 -a :6083,PROXY -t 120
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
vcl 4.0;
|
vcl 4.0;
|
||||||
|
import std;
|
||||||
|
|
||||||
# By default, Varnish will run on the same servers as the blog. Inside of
|
# By default, Varnish will run on the same servers as the blog. Inside of
|
||||||
# Kubernetes this will be inside the same pod.
|
# Kubernetes this will be inside the same pod.
|
||||||
|
|
@ -23,6 +24,11 @@ sub vcl_recv {
|
||||||
if (req.url ~ "^/admin") {
|
if (req.url ~ "^/admin") {
|
||||||
return (pass);
|
return (pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Redirect non-www to www and non-HTTPS to HTTPS
|
||||||
|
if (req.http.host ~ "tazj.in" || std.port(local.ip) == 6081) {
|
||||||
|
return (synth (750, ""));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub vcl_backend_response {
|
sub vcl_backend_response {
|
||||||
|
|
@ -38,9 +44,10 @@ sub vcl_deliver {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub vcl_synth {
|
sub vcl_synth {
|
||||||
# Execute redirects
|
# Execute TLS or www. redirect
|
||||||
if (resp.status == 301) {
|
if (resp.status == 750) {
|
||||||
set resp.http.Location = req.url;
|
set resp.http.Location = "https://www.tazj.in" + req.url;
|
||||||
|
set resp.status = 301;
|
||||||
return (deliver);
|
return (deliver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue