A
A
Alex2021-08-25 05:58:14
Nginx
Alex, 2021-08-25 05:58:14

How to proxy requests for uploading images to VK servers?

In Vkontakte, files are uploaded in three stages. Getting the url on the client, sending the file and the url to the server, and then the server, having received the data from the VK, gives it to the client for saving. Sending files from the client makes browser cors impossible.
Accordingly, I would like to proxy requests to servers through nginx in order to load the server to a minimum.
However, when proxying, you need to make sure that the url really belongs to VK, for this you need to check the post variable with the url against the list of VK domains

Domains

<cross-domain-policy>
<site-control permitted-cross-domain-policies="master-only"/>
<allow-http-request-headers-from domain="vk.com" headers="*"/>
<allow-http-request-headers-from domain="*.vk.com" headers="*"/>
<allow-http-request-headers-from domain="userapi.com" headers="*"/>
<allow-http-request-headers-from domain="*.userapi.com" headers="*"/>
<allow-http-request-headers-from domain="vk.me" headers="*"/>
<allow-http-request-headers-from domain="*.vk.me" headers="*"/>
<allow-http-request-headers-from domain="vkontakte.ru" headers="*"/>
<allow-http-request-headers-from domain="*.vkontakte.ru" headers="*"/>
<allow-http-request-headers-from domain="*.vk-cdn.net" headers="*"/>
<allow-access-from domain="vk.com" to-ports="80"/>
<allow-access-from domain="*.vk.com" to-ports="80"/>
<allow-access-from domain="vk.me" to-ports="80"/>
<allow-access-from domain="*.vk.me" to-ports="80"/>
<allow-access-from domain="userapi.com" to-ports="80"/>
<allow-access-from domain="*.userapi.com" to-ports="80"/>
<allow-access-from domain="vkontakte.ru" to-ports="80"/>
<allow-access-from domain="*.vkontakte.ru" to-ports="80"/>
<allow-access-from domain="*.vk-cdn.net" to-ports="80"/>
<allow-access-from domain="vk.me" to-ports="443"/>
<allow-access-from domain="*.vk.me" to-ports="443"/>
<allow-access-from domain="app.vk.com" to-ports="443"/>
<allow-access-from domain="*.vk-cdn.net" to-ports="443"/>
</cross-domain-policy>


And it is possible to check the secret key.

The question is, is it possible to implement it, if so, how? And how much faster will the solution work in nginx than if the request was passed through a node or php?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question