Redirect uploaded files to another server, using nginx

Posted by Serg ikS on Stack Overflow See other posts from Stack Overflow or by Serg ikS
Published on 2012-04-10T07:57:42Z Indexed on 2012/04/13 17:30 UTC
Read the original article Hit count: 300

Filed under:
|
|

I am creating a web service of scheduled posts to some soc. network.
Need help dealing with file uploads under high traffic.

Process overview:

  • User uploads files to SomeServer (not mine).
  • SomeServer then responds with a JSON string.
  • My web app should store that JSON response.

Opt. 1 — Save, cURL POST, delete tmp
The stupid way I made it work:

  1. User uploads files to MyWebApp;
  2. MyWebApp cURL's the file further to SomeServer, getting the response.

Opt.2 — JS magic
The smart way it could be perfect:

  1. User uploads the file directly to SomeServer, from within an iFrame;
  2. MyWebApp gets the response through JavaScript.

But this is(?) impossible due to the 'Same Origin Policy', isn't it?

Opt. 3 — nginx proxying?
The better way for a production server:

  1. User uploads files to MyWebApp;
  2. nginx intercepts the file uploads and sends them directly to the SomeServer;
  3. JSON response is also intercepted by nginx and processed by MyWebApp.

Does this make any sense, and what would be the nginx config for, say, /fileupload Location to proxy it to SomeServer ?

© Stack Overflow or respective owner

Related posts about post

Related posts about upload