node.js - Nodejs, PM2, and nginx deploying security? -
there few guides online show how nodejs running on server, tend skip on few details on security. bit of loaded question, , i'm not sure begin. wondering if clarify following details.
first, setup:
i have installed node locally non-sudo user because running node admin bad idea:
/home/appuser |--- nodejs/ # node install |--- bin/ |--- include/ |--- lib/ |--- share/ |--- app/ |--- node_modules/ |--- public/ # holds html templates, static files , uploaded files |--- core/ # holds main app js files |--- app.js # main nodejs program |--- config.js # configuration holds authentication details, other config stuff |--- package.jsoni can run application using
pm2doingpm2 start app.js.my
nginxconfiguration:server { listen 80; server_name mydomainname.com; location / { proxy_pass http://localhost:8080; proxy_http_version 1.1; proxy_set_header upgrade $http_upgrade; proxy_set_header connection 'upgrade'; proxy_set_header host $host; proxy_cache_bypass $http_upgrade; } }
my concerns are:
(1) application - should main app/ live inside /home/appuser?
any danger in having app files live inside non-sudo user home? if so, should app files live?
i'm wondering if
public/should in different place , not live in same folder application files. wouldn't want application source files leak out,config.jsholds sensitive information database auth details , email auth details.if should moved,
/publiclive relativeapp/?right permissions on
app/chown -r appuser:appuser app/, user owns files. there other permissions should set on application folder?
(2) pm2 - since installed nodejs , modules locally, how safely pm2 restart nodejs app after server restart?
my understanding
pm2-init.shlive in/etc/init.d/, , happens automatically if had installedpm2globally sudo.how should
pm2restart app safely using non-sudo user?
(3) nginx
how can safely serve
public/throughnginxif served this:http://mydomainname.com/publicmy app handles routes , should throw
404if route not found. possible work around , maliciously make app ornginxbrowse other directories?ie, outside of app directory
http://mydomainname.com/../../etc/path/to/secretsor, locally in app
http://mydomainname.com/public/../../config.jsare there security precautions can set in
nginxor nodejs prevent if possible?
the way adopt have files
node:node-developer. , start app undernodeuser. node-developer group developers. , set file permissions770write simple shell script logs
nodeuser , start pm2 init scirptssolved using proper permission settings. nginx runs under
nginxuser. if files public, makenginx:nginx. userpublic/../../something. nginx not have rights access it.
Comments
Post a Comment