Reputation: 1
I would like to try a Varnish config where it listens on the default port 6081 and Apache stays on 80. The idea came from this blog about varnish.
An iptables redirect then sends all 80 traffic to 6081. Doing it this way enables me to continue using my web control panel without breaking it (the panel runs on 8080 itself and also breaks when Apache's listen is changed).
Right now I am on a clean install of the server with only Apache and Varnish installed, just to see if this works as is. I can get Varnish up and running with:
curl -I 192.168.0.1:6081
However it doesn't work on the IP alone even though the iptable rule is up and running. Following are my results and settings obviously using dummy ip 192.168.0.1
iptables -L -t nat
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
REDIRECT tcp -- anywhere anywhere tcp dpt:http redir ports 6081
IP Table Rule -- (idea from here)
iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-port 6081
Results of curl -I with port 6081
curl -I http://192.168.0.1:6081
HTTP/1.1 200 OK
Date: Wed, 06 Jun 2018 21:45:20 GMT
Server: Apache/2.4.25 (Debian)
Last-Modified: Wed, 06 Jun 2018 21:08:27 GMT
Vary: Accept-Encoding
Content-Type: text/html
X-Varnish: 2
Age: 0
Via: 1.1 varnish (Varnish/6.0)
ETag: W/"29cd-56dff9168052e-gzip"
Accept-Ranges: bytes
Connection: keep-alive
Results of curl -I with no port
curl -I http://192.168.0.1
HTTP/1.1 200 OK
Date: Wed, 06 Jun 2018 21:36:49 GMT
Server: Apache/2.4.25 (Debian)
Last-Modified: Wed, 06 Jun 2018 21:08:27 GMT
ETag: "29cd-56dff9168052e"
Accept-Ranges: bytes
Content-Length: 10701
Vary: Accept-Encoding
Content-Type: text/html
/etc/default/varnish
DAEMON_OPTS="-a :6081 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,256m
/etc/varnish/default.vcl
# Default backend definition. Set this to point to your content server.
backend default {
.host = "127.0.0.1";
.port = "80";
What am I missing? Apache is on 80, Varnish is on 6081, 80 traffic is redirected to 6081 where Varnish is listening.
Upvotes: 0
Views: 12092
Reputation: 33
Let me see if I can help sort this out. So you want to try Varnish in parallel with your web server only so you can try it out. If this is the case, its not a problem.
First, port 6081 is for the admin functionality of Varnish. There's tons that you can do remotely over this port.
Assuming your web server is on port 80, you can configure your Varnish server for :8080, you could set your /etc/varnish configuration up link this:
NFILES=131072
MEMLOCK=82000
RELOAD_VCL=1
VARNISH_VCL_CONF=/etc/varnish/mysite.vcl
VARNISH_LISTEN_PORT=8080
VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1
VARNISH_ADMIN_LISTEN_PORT=6082
VARNISH_SECRET_FILE=/etc/varnish/secret
VARNISH_MIN_THREADS=100
VARNISH_MAX_THREADS=8000
VARNISH_THREAD_TIMEOUT=240
VARNISH_STORAGE_FILE=/var/lib/varnish/varnish_storage.bin
VARNISH_STORAGE_SIZE=12G
#VARNISH_STORAGE="file,${VARNISH_STORAGE_FILE},${VARNISH_STORAGE_SIZE}"
VARNISH_STORAGE="malloc,${VARNISH_STORAGE_SIZE}"
VARNISH_TTL=120
DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \
-f ${VARNISH_VCL_CONF} \
-T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \
-t ${VARNISH_TTL} \
-w ${VARNISH_MIN_THREADS},${VARNISH_MAX_THREADS},${VARNISH_THREAD_TIMEOUT} \
-u varnish -g varnish \
-S ${VARNISH_SECRET_FILE} \
-s ${VARNISH_STORAGE}"
Then, in your "mysite.vcl" configuration, you can link varnish to your web site:
backend webserver { # Define one backend
.host = "127.0.0.1"; # IP or Hostname of backend
.port = "80"; # Port for backend listener (Apache, NGINX, etc.)
Then just set up your IP Tables to accept traffic for both 8080 and 80 and you can test Varnish on :8080 and the web server on :80 independently. BTW, you should not expose the admin ports (6081, 6082, etc) to the outside.
If you decide to go with Varnish, you would put it in front of your web server. Set the varnish listen port to 80, and your web server to 8080 or any other port if they are on the same server. If they are different servers, you can leave your web server port at 80, just pull it out of the firewall so it cant be contacted directly from the outside world.
Best of luck!
Upvotes: 0
Reputation: 496
I'm not sure I totally grasp the problem here. Why the redirect from 80 to 6081?
Be default, Varnish will be exposed under 6081, this is mainly not to collide with other existing services running under popular ports like 80.
Given your setup, I'd do it the other way around. I would start Varnish under port 80 and Apache under 6081 (or any other port for that matter - I'm assuming 8089 further down the line) and of course make sure that Apache is set as a correct backend for Varnish.
After all, it's the proxy that you'd like to have in front for taking the heat.
E.g.:
/etc/varnish/default.vcl
backend default {
.host = "127.0.0.1";
.port = "8089"; # I will assume Apache runs under 8089.
}
Therefore, something like this:
$ curl -is http://127.0.0.1/foo/bar
will first hit Varnish, which in turn will try to honour the request by asking its backend (the above defined Apache).
Having said this, you can disable the 80 to 6081 redirect.
Upvotes: 1
Reputation: 36
why this way?
In my opinion you should use varnish on port 80 and two sites on apache , lets say :8080 and :8081.
APACHE>set up 2 vhosts
Site1> Play your panel on port 8080
Site2> Play your site on port 8081
Varnish>
Setup BackEnd1 for your panel
Setup BackEnd2 for your site
One at 8080 for your web-panel
and one on i.e. 8081 the actual site
Tell varnish for backend1 "panel" to pass everything to backend1 8080 (so varnish will just pass you to apache)
Tell varnish for backend2 "site" to cache whatever you like for 8081
So, with few words.
panel served from varnish and passing everything to Apache
site served from varnish and there you can apply your caching rules hits/misses etc.
Remeber to change /etc/default/varnish and set it on port 80.
PS: Never applyed this to a combo of Varnish/Apache but done it on Varnish/nginx.
You should check if apache is capable to do this. I doubt he cant.....
Upvotes: 0