Welcome! Log In Create A New Profile

Advanced

Nginx's sub_filter does not replace paths in CSS and JS

February 05, 2020 07:04AM
I have two nginx servers, let's call them nginx1 and nginx2. Nginx1 is located in a separate infrastructure and processes requests, and also provides static files for examplesite.com. Nginx2 is in a different infrastructure and processes requests, and also gives static files on request 172.22.3.15. It is necessary to make the page 172.22.3.15 open at the request of examplesite.com/new. I realized that in order for the page to be processed correctly, you need to edit the paths to static files.

To do this, a configuration was added to the nginx1 file location:

location /new {
proxy_pass http://172.22.3.15/;
}

The following settings were added to the nginx2 configuration file:

proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Server $host;
proxy_redirect off;

server {
listen 80;
server_name 172.22.3.15;
client_max_body_size 32m;
charset utf-8;
location /public/ {
alias /usr/src/app/public/;
}
location /static/ {
alias /usr/src/app/static/;
}

location / {
proxy_pass http://172.22.3.16:8000;
proxy_redirect / /new;
sub_filter '"/' '"/new/';
sub_filter "'/" "'/new/";
sub_filter_types *;
sub_filter_once off;
sub_filter_last_modified on;
proxy_set_header Accept-Encoding "";
}
}
But the problem is that in the CSS and JS files themselves, the paths are not changed. I tried to disable gzip in my configuration, but it did not bring any results. Version nginx1 1.17, and version nginx2 1.16.

P.S. I configure sub_filter to nginx2, since I do not have access to nginx1, since this is the customer’s server. I recreated a similar situation on test projects (by analogy with the production environment, let's name nginxes as nginx1 and nginx2) and set up sub_filter in the nginx1 configuration file (I didn’t make any additional settings on nginx2). But got the same problem. The test setup of nginx1 looks like this:

location /test {
proxy_pass http://192.168.29.32/;
proxy_redirect / /test;
sub_filter '"/' '"/test/';
sub_filter "'/" "'/test/";
sub_filter_types *;
sub_filter_once off;
sub_filter_last_modified on;
proxy_set_header Accept-Encoding "";

}
Subject Author Posted

Nginx's sub_filter does not replace paths in CSS and JS

!QVAS! February 05, 2020 07:04AM

Re: Nginx's sub_filter does not replace paths in CSS and JS

Francis Daly February 06, 2020 02:56PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 322
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready