Change varnish port with systemd on Fedora

Of course when you setup varnish, you likely don’t want to use the default port of varnish. In case you didn’t know, varnish runs on port 80 by default. This may not be the best port for your setup. So today, I will show you how to change the port.

I’m doing this on a Fedora 33 install but any Linux OS using systemd will be the same or similiar.

One thing I found out, is there is two ways to edit the config file. Using systemctl or using your preferred editor with the direct file path.

Systemctl method:

systemctl edit --full varnish

Or the normal preferred editor method: (file path may differ from your OS if you’re not using Fedora)

vi /lib/systemd/system/varnish.service

Then when open the file scroll down to this line:

ExecStart=/usr/sbin/varnishd -a :80 -f /etc/varnish/default.vcl -s malloc,256m

To change the port, all you need to do is edit the number 80 and change it to whatever port you want it to be.


ExecStart=/usr/sbin/varnishd -a :8081 -f /etc/varnish/default.vcl -s malloc,256m

In the above example, it will run on port 8081.

Once you’ve edited the file and saved it, restart varnish.

systemctl restart varnish

Run status to make sure it’s running on the port after restart.

systemctl status varnish

You should get a response like this:

● varnish.service - Varnish Cache, a high-performance HTTP accelerator
     Loaded: loaded (/etc/systemd/system/varnish.service; enabled; vendor preset: disabled)
     Active: active (running) since Tue 2021-01-19 21:02:59 UTC; 2 weeks 6 days ago
   Main PID: 30050 (varnishd)
      Tasks: 217
     Memory: 114.7M
        CPU: 9min 528ms
     CGroup: /system.slice/varnish.service
             ├─30050 /usr/sbin/varnishd -a :8081 -f /etc/varnish/default.vcl -s malloc,256m
             └─30069 /usr/sbin/varnishd -a :8081 -f /etc/varnish/default.vcl -s malloc,256m

And you’re all set! Have an amazing day!

Leave a Reply