Skip to content

Serve ad zone JS code locally to circumvent adblocks

jzemlo edited this page Jan 16, 2020 · 7 revisions

/etc/nginx/sites-enabled/YOUR-SITE

# can be put in /etc/nginx/nginx.conf if you use multiple virtual servers
proxy_cache_path  /tmp/ads-cache  levels=1:2    keys_zone=ads:1m    inactive=24h  max_size=10m;

server {

# ... other site configuration options ... #

    location /main.js {
        expires 1h;
        proxy_pass https://ADSERVER_DOMAIN/main.js;
        proxy_ssl_server_name on;
        proxy_buffering on;

        proxy_cache            ads;
        proxy_cache_valid      200  1h;
        proxy_cache_use_stale  error timeout invalid_header updating;
    }
}

Then you need to modify adunit code ad replace script src with locally served version e.g.

<script type="text/javascript" src="https://YOUR-SITE/main.js" async></script>

OR simply

<script type="text/javascript" src="/main.js" async></script>
You can’t perform that action at this time.