Where to put project files with nginx
Looking at the /usr/share/doc/nginx/README.Debian
file, we can see this warning:
README for Debian
-----------------
Files under /var/www/ are not supported as per Debian Policy.
Please see: http://lintian.debian.org/tags/dir-or-file-in-var-www.html and,
http://www.pathname.com/fhs/pub/fhs-2.3.html#THEVARHIERARCHY for more
details and explanations.
After some unsuccessful research (I probably look at the wrong places...), I wonder if:
- This warning is a general advice ("don't put your files in
/var/www
") or if it just means that a standard Debian package installation should not install files under/var/www
. - If we are actually discouraged to place the production websites in
/var/www
, where should I put them?
Thanks by advance!
Reading again the whole thing, IMHO it's nonsense to put your docroot(s) under /usr. It's your data, not nginx's. So, somewhere in /var is the right place obviously. Think about backups. your data is in /var, and websites are part of it. /usr is not, /usr contains packages data (software system data).
Now, my attempt on "why this Debian policy"
It's risky to expose a generic path by default on a webserver. By putting the default setting to /usr/share/nginx/something, Debian ensures that the webserver will not start serving files it should not.
Example
You already have an apache with a docroot in /var/www and you install nginx for something else than apache job (ex serving some static files for speed). So you use a "bare" nginx without PHP nor htaccess support : you don't want to see nginx starting to serve files handled by apache : PHP source files and files that should be protected by htaccesses.
So to my understanting, the Debian policy is not "it's bad practice to have the docroot in /var/www (or rather /var/www/), but more "it's bad pratice for an httpd package to start serving /var/www by default".
This message/behavior is just a (safe) packaging policy. Not a sysadmin good practice
According to http://lintian.debian.org/tags/dir-or-file-in-var-www.html
Debian packages should not install files under /var/www. This is not one of the /var directories in the File Hierarchy Standard and is under the control of the local administrator. Packages should not assume that it is the document root for a web server; it is very common for users to change the default document root and packages should not assume that users will keep any particular setting.
So, this simply seems like a warning for package authors to not assume that /var/www
is the document root, and not to install files there. Indeed, on my Debian system, it's not even the default root, where the default root is /usr/share/nginx/html
(don't recall if I had nginx
installed from the Debian collection or directly from nginx.org).
I see nothing that prevents you from placing a production site in /var/www
.
/srv/www is where I keep my web application files. I leave /var/www for web packages that I install with apt such as wordpress. If I set up wordpress by hand, I will put it in /srv/www.
Having said all of that, I have an issue with debian NOT creating the /var/www directory by default despite setting that directory as the home of the www-data user. Installing nginx does not create the directory either. Installing apache does. It is just arbitrary.