Answer the question
In order to leave comments, you need to log in
How to make a regular expression for nginx location for proxy?
There is a task: to make a proxy of this type
site.ru/http://another-site.ru/images/1.png It is necessary that another-site.ru/images/1.png
opens
at this URL
Help with the location, which should there be a regex there?
Answer the question
In order to leave comments, you need to log in
In general, he solved this problem himself. In my case it is done like this:
location ~* ^.*\/(?<pschema>.*)?:\/\/(?<phost>[a-z0-9\.\-]*)\/(.*)\.(eot|otf|ttf|woff|svg|css|js|png|jpg|gif)$ {
rewrite ^.*\/(?<pschema>.*)?:\/\/(?<phost>[a-z0-9\.\-]*)(?<ppath>.*)$ $ppath break;
proxy_pass $pschema://$phost;
proxy_set_header Host $phost;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
break;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question