user782860
user782860

Reputation: 2779

What is the proper folder to serve node.js webapps from on a server?

As a reference, say a developer builds a vanilla php webapp with a ngnix server. It would make sense to host the web files in the /srv/www directory on a VPS. The owner and group of this /srv/www is nginx.

What is the correct directory to host webapps when running said webapp with nodejs? What is the correct folder permissions for said directory? And of course, please keep in mind security is very important. The OS, in this case is Centos 6.5.

Upvotes: 2

Views: 1901

Answers (1)

Peter Lyons
Peter Lyons

Reputation: 146014

Permissions

Generally for permissions I set things up as follows:

  • most files are 440 owned by myapp with group set to admin
    • if the app needs to write to them, files can be 640
    • if the administrator commonly wants to write to them, files can be 460
  • most directories are 550 owned by myapp with group admin
    • if the app needs to write to them, directories can be 750
    • if the administrator commonly wants to write to them, they can be 570 However, as times advance and PaaS becomes more dominant, that style becomes less important and cooperation across multiple apps running in the same host OS on the same filesystem is less and less important due to virtualization and all it's many forms.
  • Deviate from those baselines on a case-by-case basis as necessary for your app to operate correctly and still be secure.

Filesystem Layout

There are a few conventions here. The most formal being the linux Filesystem Hierarchy Standard which has long-running and more-or-less agreed upon conventions.

FHS Style

  • App code goes in /opt/myapp
  • Data and runtime state go in /var/opt/myapp
  • Log data goes in /var/opt/log/myapp
  • config goes in /etc/opt/myapp
  • your app can run as a user account named myapp and have appropriate FS read/write permissions

PaaS Style

  • mostly it's a moot point since your PaaS vendor (heroku, nodejitsu, modulus, etc) will dictate this for you
  • you just make your app into an npm module and you're done

Docker Style

For the docker world, it's similar to PaaS in that it doesn't matter all that much, but, for example for phusion's baseimage-docker things will "just work" for you if you install your code to /home/app within the container

Upvotes: 7

Related Questions