A
A
Alexander Savenko2017-07-04 00:39:12
Nginx
Alexander Savenko, 2017-07-04 00:39:12

How to make a proxy in nginx for many images from an external site?

Hello!
I am optimizing the site according to the recommendations from pagespeed. There is a problem on "Use browser cache". I did it for local files, but I have external resources and I found an interesting topic with Yandex metrics.

location = /metrika.js {
  expires 30d;
  proxy_pass https://mc.yandex.ru/metrika/watch.js;
  proxy_set_header Host mc.yandex.ru;
}

But besides Yandex, there are many more images from a third-party resource. How to make a universal rule?
For example:
Link to an image from a supplier:
https://external.ru/catalog/img1.jpg
And I want this link to open as:
https://mysite.ru/catalog/img1.jpg
How can I do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Savenko, 2017-07-05
@savenko

I tried options:

location ~* ^/catalog/(.*)$ {
     proxy_pass $scheme://external.ru/catalog/$1;
     proxy_set_header Host      $host:$server_port;
     proxy_set_header X-Real-IP $remote_addr;
}

and
location ~* /catalog/(.*)$ {
     proxy_pass $scheme://external.ru/catalog/$1;
     proxy_set_header Host      $host:$server_port;
     proxy_set_header X-Real-IP $remote_addr;
}

and
location /catalog {
     proxy_pass $scheme://external.ru;
}

Does not work(((

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question