Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

http_sub_module / sub_filter of nginx and reverse proxy not working

Tags:

I am trying to reverse proxy my website and modify the content. To do so, I compiled nginx with sub_filter. It now accepts the sub_filter directive, but it does not work somehow.

server {     listen       8080;     server_name  www.xxx.com;      access_log  /var/log/nginx/www.goparts.access.log  main;     error_log  /var/log/nginx/www.goparts.error.log;     root   /usr/share/nginx/html;     index  index.html index.htm;      ## send request back to apache1 ##     location / {        sub_filter <title> '<title>test</title>';  sub_filter_once on;        proxy_pass  http://www.google.fr;      proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;      proxy_redirect off;      proxy_buffering off;      proxy_set_header        Host            $host;      proxy_set_header        X-Real-IP       $remote_addr;      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;     } } 

Please help me

like image 511
thms0 Avatar asked Aug 08 '15 12:08

thms0


People also ask

What is Sub_filter in nginx?

subs_filter allows replacing source string (regular expression or fixed) in the NGINX response with destination string. Substitution text may contain variables.

What is nginx proxy buffer?

Proxy buffering means that NGINX stores the response from a server in internal buffers as it comes in, and doesn't start sending data to the client until the entire response is buffered.

How to install http substitutions filter in Nginx Plus?

Install the HTTP Substitutions Filter module. For Amazon Linux, CentOS, Oracle Linux, and RHEL: For Debian and Ubuntu: Put the load_module directive in the top‑level (“ main ”) context of NGINX Plus configuration file, nginx.conf:

How to enable http_realip_module in Nginx?

This module is not built by default, it should be enabled with the --with-http_realip_module configuration parameter. This module is needed when your NGINX server is behind a L7 load balancer or another device that passes the client's IP address in an HTTP header.

How do I load a module in Nginx Plus?

Put the load_module directive in the top‑level (“ main ”) context of NGINX Plus configuration file, nginx.conf: Perform additional configuration as required by the module.

What is the ngx_http_sub_module?

The ngx_http_sub_module module is a filter that modifies a response by replacing one specified string by another. This module is not built by default, it should be enabled with the --with-http_sub_module configuration parameter.


1 Answers

Check if the upstream source has gzip turned on, if so you need

proxy_set_header Accept-Encoding ""; 

so the whole thing would be something like

location / {     proxy_set_header Accept-Encoding "";     proxy_pass http://upstream.site/;     sub_filter_types text/css;     sub_filter_once off;     sub_filter .upstream.site special.our.domain; } 

Check these links

  • https://www.ruby-forum.com/topic/178781
  • https://forum.nginx.org/read.php?2,226323,226323
  • http://www.serverphorums.com/read.php?5,542078
like image 158
Mike Lee Avatar answered Sep 28 '22 06:09

Mike Lee