I have a Ubuntu 16.04 Nginx server environment with several CMS (WordPress) websites under document root.
All the site directories have www-data
as owner and group, recursively.
According to some security consultation I got, this is problematic because data from one site could alter any other adjacent site (for example, a malicious module installed in one the CMSs of one of the sites).
I assume that the solution would be to change this command which I always run after adding a new site (and also in cron after updates that change owner and group):
chown -R www-data:www-data /var/www/html/*
To some conditional command that changes these characteristics not just to www-data
but to the actual name of the site dir.
To clarify, the owner of each site dir should be domain.tld
and the group should also be domain.tld
(I always name site dirs as per the site's domain.tld).
What could be such a conditional command?
Note: The Nginx user as well as the dir /var/www/html/
will both stay with www-data:www-data
.
Update for G-Man:
I have yet to test but I think this is good if you pass ${domain}
as the first argument for a variable ($1
):
chown -R ${domain}:${domain} ${domain}/*
Though I'd keep it:
chown -R ${domain}:www-data ${domain}/*
Of course, adduser ${domain} --disabled-password --disabled-login
is needed before, if wasn't done.
domain1
site *runs as* thedomain1
user. Have you addressed that? – G-Man Says 'Reinstate Monica' Jan 16 '18 at 22:12${domain}:www-data
is probably good enough if you use modes 644 and 755. If you use 664 and 775, you need${domain}:${domain}
. (2) As I said, I may be missing something; I don’t know Nginx or CMS. But I still don’t see anything that causes module(s) from thedomain1
site (directory tree) to execute as thedomain1
user. – G-Man Says 'Reinstate Monica' Jan 17 '18 at 06:13