D
D
Dmitry2015-04-09 16:51:16
Nginx
Dmitry, 2015-04-09 16:51:16

NGINX: how to serve a remote file with "native" headers, changing its contents on the fly?

Good day.
There is a location for a text/javascript file (http(s)://mydomain.com/file.js), the file itself must be taken from a link to an external resource (http(s)://somedomain.com/file.js).
It is necessary to return the file http(s)://somedomain.com/file.js when requesting http(s)://mydomain.com/file.js , changing the content on the go (replacing one address with another in several places) and substituting the headers of the remote file.
Is a subject possible, and if so, how? And if not, how can you achieve what you want (give away a remote file (tightened by curl? ..), changing headers and contents on the fly)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
egor_nullptr, 2015-04-09
@blasterdick

nginx.org/ru/docs/http/ngx_http_sub_module.html

D
doctop, 2017-02-05
@doctop

maybe a working example?
my version doesn't work ( images is not replaced with images/block )

server {
listen 80;
server_name mydomain.com;

location /file.js {
proxy_pass http://somedomain.com;
proxy_set_header Accept-Encoding "";
sub_filter 'images' 'images/block';
sub_filter_once off;
sub_filter_types *;
}
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question