Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Using NGinx as an image server with mongodb as a DB and node as app server...?

Using NGinx as an image server with mongodb as a DB and node as app server...?


I want to host a social type of site. It will be on node (or vertx) . My question is........ if I have a separate image Server on my Local area network.. when a user uploads a file should the file be saved to the image -nginx server and then the database told about it and given a link for the picture?

for instance it would be like this:

db.users.find('profilepicture' : 1)

profilepicture: localaddressoftheneginxserver/imagefolder/imagename.jpg

Am I thinking things through correctly? Have the image served on a separate nginx server... have the database not include the actual picture but a link to the picture... so when a client connects to the App Server and asks for a particular picture it queries the database, the database sends the link to the app server... and then the app server informs the users computer of the pictures location?

would that work? i'm just a little confused about how someone on the outside could connect to an app server and then also be able to connect to an image server on the same local area network even if they had the address. Would the image server need to be some separate IP?

Problem courtesy of: NoTiG


We had a similar use case and the way we handled it was the following:

  • The image is uploaded to the application server first, where it is stored as a temporary file.
  • (optional) Run some validation on the image format, resize it if needed.
  • Transfer / deploy the image from the application server to the image server (could be nginx, a CDN, Amazon S3, etc.).
  • Update the DB record with the location of the image to be loaded by the client.
  • Delete the temporary file from the application server.

That way, the HTTP client only ever communicates with the Application Server which retains all the business logic / security / access control / etc. It only reads from the image server.

Actually letting a user directly write to the image server could be a security risk because this type of server typically doesn't have much control on what is uploaded (unlike the application server).

Solution courtesy of: Christophe L


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Using NGinx as an image server with mongodb as a DB and node as app server...?


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription