18.05.2016 Views

Mittwoch, 18. Mai, 2016

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Finishing Angular TODO application and deploying to production 149<br />

• Serving static files like images, CSS, js, and HTML. Node may be less efficient compared to<br />

using a proper static file web server (Node may also be faster in select scenarios, but this is<br />

unlikely to be the norm). On top of files serving more efficiently, you won’t have to worry<br />

about handling eTags or cache control headers the way you would if you were servings things<br />

out of Node. Some frameworks may handle this for you, but you would want to be sure.<br />

Regardless, still probably slower.<br />

• More easily display meaningful error pages or fall back onto a static site if your node service<br />

crashes. Otherwise users may just get a timed out connection.<br />

• Running another web server in front of Node may help to mitigate security flaws and DoS<br />

attacks against Node. For a real-world example, CVE-2013-4450²²⁴ is prevented by running<br />

something like Nginx in front of Node²²⁵.<br />

So, with being convinced that having NGINX in front of Node.js application is a good thing,<br />

following are the steps on how to install and configure it. First, update the apt-get package lists<br />

with the following command:<br />

1 sudo apt-get update<br />

Then install NGINX using apt-get:<br />

1 sudo apt-get install nginx<br />

Now open the default server block configuration file for editing:<br />

1 sudo vi /etc/nginx/sites-available/default<br />

and add this to it:<br />

1 server {<br />

2 listen 80;<br />

3<br />

4 server_name meantodo.com;<br />

5<br />

6 location / {<br />

7 proxy_pass http://127.0.0.1:1337;<br />

8 proxy_http_version 1.1;<br />

9 proxy_set_header Upgrade $http_upgrade;<br />

10 proxy_set_header Connection 'upgrade';<br />

11 proxy_set_header Host $host;<br />

12 proxy_cache_bypass $http_upgrade;<br />

13 }<br />

14 }<br />

²²⁴http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2013-4450<br />

²²⁵http://blog.nodejs.org/2013/10/22/cve-2013-4450-http-server-pipeline-flood-dos/

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!