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. Required fields are marked *

Sorry, I’m using google translator, if don’t add pronouns, it may generate an incorrect translation. You wrote in the article that you added the “traffic-advice” file to the .well-known directory, but if check your site with a traffic-advice checkup tool, you still get a 404 error when accessing /.well-known/traffic-advice. I’m sorry if my question was not clear

Clean and clear now. I don’t use ‘traffic-advice’ on my personal blog. This site is hosted on shared hosting server I have no access to. I use it on my other websites.

This post was very informative. Thanks for writing it, and for adding links to the various resources and the little checkup tool!

much easier solution:

location = /.well-known/traffic-advice {
default_type application/trafficadvice+json;
return 200 ‘{“user_agent”:”prefetch-proxy”,”google_prefetch_proxy_eap”:{“fraction”:1.0}}’;
}

↑ Up