Live Blog

Resolving .well-known/traffic-advice 404 Errors

Introduction

You might be seeing the following errors in your Nginx log pilling up.

2024/09/19 15:03:56 [error] 807292#807292: *2418 open() "/var/www/domain.com/htdocs/.well-known/traffic-advice" failed (2: No such file or directory), client: 142.250.32.40, server: domain.com, request: "GET /.well-known/traffic-advice HTTP/2.0", host: "domain.com"

What is .well-known/traffic-advice?

The traffic-advice file, located in the /.well-known/ directory, is a JSON configuration file, although it doesn’t have a .json extension, likely for future adaptability.

Currently utilized only by Chrome, this file communicates with prefetch proxies that visit your website, instructing them whether or not to prefetch your pages and, if so, to what extent. This extent is represented as a percentage value between 0.0 (0%) and 1.0 (100%).

Chrome Privacy Preserving Prefetch Proxy bot

The Chrome Privacy Preserving Prefetch Proxy bot is Chrome trying to make pages load faster for you. It secretly fetches stuff from sites you might visit next so it’s ready when you click. It’s also important not to share too much info with those sites, keeping things private.

Google says this Chrome feature helps pages load faster by preloading content from other sites you might visit without spilling your info. They’ve seen pages load up to 30% quicker with this trick!

Private prefetch proxy in Chrome  |  Blog  |  Chrome for Developers
Speeding up Largest Contentful Paint (LCP) with cross-site prefetching.
developer.chrome.com

I also found this specification proposal for private proxy pre-fetch.

private-prefetch-proxy/traffic-advice.md at main · buettner/private-prefetch-proxy · GitHub
Proposal to use a CONNECT proxy to obfuscate the user IP address for privacy-enhanced prefetching. – private-prefetch-proxy/traffic-advice.md at main · buettner/private-prefetch-proxy
github.com

Resolution

So, how do we eliminate these 404 errors and properly process these requests? There are a few steps to complete.

Nginx

Wherever you’ve set the root of your Nginx server/site, create a .well-known directory

sudo mkdir -p /sites/domain.com/.well-known

You then want to create the traffic-advice file in the new directory. You can use your favourite editor

vi /sites/domain.com/.well-known/traffic-advice

Add the following lines to the /sites/domain.com/.well-known/traffic-advice file

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

We now need to configure Nginx to return this file as application/trafficadvice+json which is a custom MIME content type.

Edit /etc/nginx/nginx.conf and add these lines:

 location ^~ /.well-known/traffic-advice {
    allow all;
    types { } default_type "application/trafficadvice+json; charset=utf-8";
    alias /sites/domain.com/.well-known/traffic-advice;
 }

Now you can reload Nginx

systemctl reload nginx.service 

GridPane Nginx

On GridPane, it’s not so different; create a .well-known directory in the /var/www/domain.com/htdocs folder for your domain.

mkdir -p /var/www/domain.com/htdocs/.well-known

We’ll do the same as with Nginx and create the traffic-advice file in the new directory. You can use your favourite editor

vi /var/www/domain.com/htdocs/.well-known/traffic-advice

Add the following lines to the file.

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

Like Nginx, configure Nginx to return this file as application/trafficadvice+json, a custom MIME content type.

Edit nano /var/www/domain.com/nginx/well-known-main-context.conf

 and add these lines:

 location ^~ /.well-known/traffic-advice {
    allow all;
    types { } default_type "application/trafficadvice+json; charset=utf-8";
 }

Now you can reload Nginx

systemctl reload nginx.service 

Testing

To test your success, run the following command from a Linux shell.

❯ curl --head https://domain.com/.well-known/traffic-advice                                                                                                     
HTTP/2 200
date: Thu, 19 Sep 2024 17:49:06 GMT
content-type: application/trafficadvice+json; charset=utf-8
content-length: 97
last-modified: Thu, 19 Sep 2024 17:48:22 GMT
etag: "66ec63e6-61"
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
server: Prometheus
pre-cognitive-push: Enabled
quantum-flux-capacity: Omega
strict-transport-security: max-age=31536000
cache-control: public, no-cache
referrer-policy: strict-origin-when-cross-origin
accept-ranges: bytes
0 Shares: