Traffic Advice: How to Configure Apache or Nginx for Chrome Privacy Preserving Prefetch Proxy
, updated:

Traffic Advice: How to Configure Apache or Nginx for Chrome Privacy Preserving Prefetch Proxy

I have found repeating 404 errors caused by the request https://www.exampe.com/.well-known/traffic-advice by “Chrome Privacy Preserving Prefetch Proxy” bot so I read several papers:

After I didn’t read this one 🙂

I decided to put recommended directive

[{
  "user_agent": "prefetch-proxy",
  "google_prefetch_proxy_eap": {
    "fraction": 1.0
  }
}]

to the file “traffic-advice” in .well-known directory. No more 404 errors, hooray.

File without extension with hybrid json MIME type – why so complicated?

If it were that simple, this article wouldn’t exist so… I froze on an unusual place: the MIME type.

Documentation recommends delivering suffixless file with a hybrid json MIME type application/trafficadvice+json. Why so complicated?

Robrwo summarized it well in this Github issue so it’s enough just to quote him:

Adding a custom MIME type “application/trafficadvice+json” basically means that a special configuration for this file needs to be added to the web server configuration.

If the URL path was simply “/.well-known/traffic-advice.json” then it would have a reasonable MIME type based on the file extension, and there would be less work for site maintainers.

Ideally, website maintainers would simply add a file and let the web server serve it with the appropriate MIME type. Instead, this will require special configuration just to handle a special case, which can be a barrier to adoption.

So answer on my question “how I should return application/trafficadvice+json MIME type for .well-known/traffic-advice on my website without writing an extra script or alter my nginx configs” is none.

How to deliver application/trafficadvice+json MIME type for Apache or Nginx?

After creating of the file without extension Apache solution is to edit the main .htaccess file with these lines:

RewriteRule "^/.well-known/traffic-advice$" - [T=application/trafficadvice+json,END]

Nginx solution (ehm, my own snippet) depending on your stack may looks from the most simplest:

# Private Prefetch Proxy
# https://developer.chrome.com/blog/private-prefetch-proxy/
location /.well-known/traffic-advice {
   types { } default_type "application/trafficadvice+json; charset=utf-8";
}

to more advanced like this:

# Private Prefetch Proxy
# https://developer.chrome.com/blog/private-prefetch-proxy/
location /.well-known/traffic-advice {
   types { } default_type "application/trafficadvice+json; charset=utf-8";
   alias /var/www/html/.well-known/traffic-advice;
   allow all;
}

Final tests

After command service nginx reload either use this traffic-advice checkup tool or wget to download the https://www.example.com/.well-known/traffic-advice in order to see proper application/trafficadvice+json MIME type and the best of all: no 404.

Leave a Reply

Your email address will not be published.

↑ Up