P
P
playray2018-12-04 08:24:41
Nginx
playray, 2018-12-04 08:24:41

How to proxy files on another site in nginx?

I'm moving to php-fpm
There are image urls on the page in the form https://site1.me/i/img/img.site2.ru/cat1/cat2/cat3...
The actual address of the image is img.site2.ru/cat1/cat2 /cat3/picname.big.jpg which is actually the url
It should be shown as if the pictures are on site1
On Apache, everything worked through the .htaccess file in the /i/ folder
With the following content:
RewriteEngine on
php_value default_socket_timeout 1
RewriteRule "^img/(. *)$" " http://$1 " [P]
RewriteRule "^imgs/(.*)$" " https://$1 " [P]
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2018-12-04
@dodo512

nginx.org/ru/docs/http/ngx_http_core_module.html#r...

location ~ ^/i/imgs?/(.*)$ {
    resolver 8.8.8.8;
    proxy_pass https://$1;
}

If there is only one img.site2.ru domain, then it is possible without a resolver.
location ~ ^/i/imgs?/img\.site2\.ru/(.*)$ {
    proxy_pass https://img.site2.ru/$1;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question