Nginx's subs_filter seems not to work

I have an old WP that I recently converted to http/2, and the speed improvements were beautiful, to say the least. :smile:

However, there are several assets that are spread across several hostnames (all pointing to the same server root) because in the past dividing resources across hostnames was a boosting technique we were used to.

E.g.:

css.example.com
js.example.com
img.example.com

All of the above hostnames have their root exactly on /var/www/example.com/htdocs/.

Even worse, some assets are referenced by https://example.com and others by https://www.example.com.

Now I want Nginx to replace all these hostnames to the normalized form https://www.example.com, but there is no way to achieve this simple goal.

I read about subs_filter here: EasyEngine 3.3 released with Full-Page Redis Cache support. I then tried to add this to /var/www/example.com/conf/nginx/nginx.conf:

subs_filter https://example.com/ https://www.example.com/;
subs_filter https://css.example.com/ https://www.example.com/;

But no way to achieve my text replacement. :frowning:

I’m using Nginx 1.9.10 (I run an ee stack upgrade --all prior to trying this test).

Finally, I’d like to use the subs_filter to force some stubborn customers to make use of my CDN to serve their huge image files. Currently the only way to tho this is using WP Super Cache support for CDNs, but I want something they can’t break.

Thanks!

Anyone? Any ideas? :smiley:

Have you figured this out?

I’m trying to set up a local CDN with no luck. Created a cdn subdomain, updated subs filter. It doesn’t work.

I use Lew Ayotte’s code he provided from his blog and it works great!

https://lewayotte.com/2016/03/22/deliver-all-the-things-from-nginx-with-subs-filters-in-cloudfront-for-wordpress/

However if I try to customize it to only pass certain MIME types it does not work with Autoptimize for some reason, but it works well with Autoptimize if you use it like in the blog link.