nginxnginx-reverse-proxyproxypass

replace content string with nginx proxy_pass


I use this content in my subdomain: https://sub.highping.com.tr/lorem

I want replace all "ipsum" strings when nginx_proxy process.

Can I do it whith ngx_http_sub_module ?

So I tried but couldn't do it.


location  /lorem {

proxy_pass https://raw.githubusercontent.com/subhanahmet/lorem/main/loram.js;

sub_filter_once off;
sub_filter_types text/html;
sub_filter "ipsum" "sometext";
sub_filter_once on;

}


Solution

  • It might be that your loram.js file is not served as "text/html" Content-Type.

    location /lorem {
        proxy_pass https://raw.githubusercontent.com/subhanahmet/lorem/main/loram.js;
    
        proxy_set_header Accept-Encoding "";
        sub_filter_types text/html;
    
        sub_filter 'ipsum' 'sometext';
        sub_filter_once off;
    }
    

    After updating the configuration, make sure you restart nginx.

    sudo systemctl restart nginx