How can I add gzip headers to specific content types?

  • What version of Ghost are you using? 3.1.4
  • What configuration? Digital Ocean 1Click Installer
  • What browser? any

Hi all,

I have embedded a Unity WebGL build into a custom page template on my website. This works as intended. However the load time is a little slow because the files being served are gzipped despite the server not sending this header information. You can see the recommendations from the Unity documentation here.

I’ve attempted to add the following behind my well-known location block in /etc/nginx/sites-enabled/my.domain.conf and restarting nginx but it seems to have no effect.

location ~ .+\.unityweb$ {
    add_header Content-Encoding gzip;

The result is:

server {
listen 80;
listen [::]:80;

server_name my.domain;
root /var/www/ghost/system/nginx-root; # Used for SSL verification (

location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $http_host;


location ~ /.well-known {
    allow all;

location ~ .+\.unityweb$ {
    add_header Content-Encoding gzip;

client_max_body_size 50m;

Is there anything else I need to do specifically for Ghost CMS to make this change work? I’m also not overly familiar with nginx so is this location correct? I have been using this forum thread to get the Content Encoding syntax.

It turns out (after a LOT of mucking around) that I needed to add the following to my unityweb location.

root /var/www/ghost/content/themes/my-theme;

I assume this has something to do with the way nginx is proxying everything to ghost and how ghost is handling urls or something? Can anyone shed any light on why setting the root works so I can learn from it in future?