You can set up a directory so that files created in it belong to a particular group regardless of the effective group ID of the process which creates them. This is called BSD semantics and you should set SGID bit for the directory to enable it:
chgrp domain /var/www/domain
chmod g+s /var/www/domain
This does not change group of the files and directories already in
/var/www/domain, you'll need to take care of that manually (for example using
chgrp above). Note that all subdirectories subsequently created in the directory will also inherit SGID, automatically enabling BSD semantics for the subdirectores as well.
The same semantics is not possible for the owner, though.
If you need to achieve this for both the owner and the group you probably need to ensure that the code which creates files under
/var/www/domain runs with effective user
domain and effective group
domain. You can use
sudo to do this:
sudo -u domain -g domain your_command
domain is the primary group of user
domain, the following will suffice
sudo -u domain your_command
Since this solution easily takes care of both owner and group there is no need for BSD semantics.
If you don't want to change the effective user and group of the process which creates the files (for example because it is a large server performing a number of other unrelated functions), you may need to externalize the part of the functionality which creates the files into a separate process whose effective UID and GID can be changed accordingly or you can use BSD semantics and try to achieve your ultimate goal by relying solely on the group.