Nginx Proxy Google Analytics

Improve Page Speed Score

Nginx Proxy Google Analytics

by John Vincent

Posted on April 26, 2017

Leverage Browser Caching Warning on Nginx

Page Speed flags browser caching of Google Analytics. The following is a way to address this.

I have seen this documented somewhere else, this is my implementation.




Nginx configuration

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;


    location = /analytics.js {
        expires 31536000s;
        proxy_set_header Pragma "public";
        proxy_set_header Cache-Control "max-age=31536000, public";

Restart Nginx

sudo nginx -t
sudo systemctl reload nginx
sudo systemctl restart nginx