Why would I want to host a Node.JS application behind a webserver?
There are several good reasons to stick another webserver in front of Node.js:
- You can offload SSL to the webserver, with free LetsEncrypt or purchased certificates.
- The cost.
- This allows multiple customers to host multiple apps on a shared servers, making it affordable for more users.
- Protected URL directories, like in Apache can put a username and password on an App.
- Not having to worry about privileges/setuid for the Node.js process.
- Only root can bind to port 80 typically. If you let LiteSpeed worry about starting as root, binding to port 80, and then relinquishing its root privileges, it means your Node app doesn't have to worry about it.
- Serving static files like images, css, js, and html. Node may be less efficient compared to using a proper static file web server
- (Node may also be faster in select scenarios, but this is unlikely to be the norm).
- On top of files serving more efficiently, you won't have to worry about handling eTags or cache control headers the way you would if you were servings things out of Node.
- LiteSpeed's lscache with also help accelerate your site is the same images are being sent constantly.
- You can more easily display meaningful error pages or fall back onto a static site if your node service crashes. Otherwise users may just get a timed out connection.
- Running another web server in front of Node may help to mitigate security flaws and DoS attacks against Node.
- For a real-world example, CVE-2013-4450 is prevented by running something like Nginx in front of Node.
- LiteSpeed is particularly good at seeing off DDoS attacks
Was this article helpful?