0

I was thinking of building a web app which would be single page, using only javascript to update the page (no reloads). So I'm confused about what kind of setup to use.

I'm kinda new to both technologies, so I was wondering if you can set up nginx to serve html (+ js, css and other static resources) like a normal web server and then from those pages connect to a node.js websocket server (same host/ip) using something like socket.io?

Is this setup good or bad? What would be a better approach? What advantage would I get if I serve html pages in node.js and get static resources (css, js, images, ...) from nginx?

2 Answers 2

3

I dont think serving few images and static htmls from nodejs itself will ever be a bottleneck , ideally a front end proxy like nginx is required if you need to load balance between multiple servers and also for exposing you internal http services as https traffic. If you dont have that requirement it would be a overkill imho.

Sign up to request clarification or add additional context in comments.

6 Comments

I was thinking of that primarly because of decoupling. So I could have websockets-only node.js app. So doing both http and websockets in one app is more than ok? I really don't want it to grow into a big ball of mud.
Just to let you know before you dive too deep...nginx still has no support for websockets :)..
I know. Maybe the whole nginx idea from the start was a little over engineered... :)
well as far as decoupling is concerned you can have your websocket traffic connect to a different port (one on which socket.io runs) from your simple html server's pages
AND if you reaaaallly have to go for a proxy there is a good option ...github.com/nodejitsu/node-http-proxy
|
1

From various comments in the currently accepted answer, I wanted to note the following.

NodeJS itself does a pretty decent job of delivering static content, as good as nginx in many cases.

Trying to proxy a WebSocket connection is problematic at best currently, as most proxy code simply doesn't support it. Currently, it is best to use Node directly.

If/When you have a need to deliver static content separately, best to use another domain and a CDN at that point.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.