0

I have nginx sitting in front of a web application running on localhost listening on port 8085 whose HTML source files I cannot modify. These source files load Google fonts via http rather than https and this generates mixed content warnings in my users browsers.

As a result I'd like to rewrite the http calls to the Google fonts on the fly as the pages are proxied through nginx on their way to my users. In other words I want to rewrite:

http://fonts.googleapis.com/css?family=Roboto:400,700&subset=latin,cyrillic,greek,vietnamese

to:

https://fonts.googleapis.com/css?family=Roboto:400,700&subset=latin,cyrillic,greek,vietnamese

in the page /application/example.html

I have the following block in my reverse-proxy.conf file which I thought would do it:

location /application/ { proxy_pass http://127.0.0.1:8085; # Replace http calls to Google with https ones proxy_set_header Accept-Encoding ""; sub_filter 'http://fonts.googleapis' 'https://fonts.googleapis'; sub_filter_once off; access_log off; } 

but it doesn't appear to work. I've seen mentions that I need to enable sub_filter when compiling nginx but I didn't compile it - it was installed via apt-get on Debian. Is there a way to determine if sub_filter is enabled ?

Just to be clear, I'm not trying to rewrite my site URL's to use https instead of http, I'm trying to rewrite non-https off-site URL's. This seems to be a trivial problem but I've Googled extensively but can't find any working examples so any advice would be much appreciated.

6
  • Why can't you fix the web application? That may well be trivially easy, especially if they're just templates or static files. Commented Aug 16, 2018 at 13:49
  • Unfortunately I can't - the source files won't be served if they have been modified. This decision was taken by the developer of the application. If I could do it that way then I would have done so already. Commented Aug 16, 2018 at 18:30
  • That means the developer is dead? I hope you plan to replace that app as soon as practical, then. Commented Aug 16, 2018 at 20:21
  • No the developer is not dead and the application is unique so I won't be replacing it. It's done to avoid people breaking the HTML code by making changes. Limited changes can be made via a plugin but sadly it's not possible to change the part of the code that I want that way. Commented Aug 16, 2018 at 21:29
  • If the developer is alive, why haven't they fixed it?! This is so trivial and ridiculous that you really should be pushing them hard on this. Commented Aug 16, 2018 at 21:51

1 Answer 1

0

The sub_filter* directives require the ngx_http_sub_module module which is not built by default, it should be enabled with the --with-http_sub_module configuration parameter.
Check with nginx -V.

1
  • Thanks. I've just checked and the version that I'm using was built with --with-http_sub_module. So in theory it should work ... Commented Aug 16, 2018 at 11:50

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.