Nginx change default user

Default nginx runs on the user www, www-data of something alike.

You can change it. Be sure that you are aware of the security risks!
Don’t change it to a user that has access to sudo!

In /etc/nginx/nginx.conf on line #1 change the user.

#user www-data;
user deployment;

And change the user for php-fpm (If you’re using php-fpm 😉)

Create a file in /etc/php/7.2/fpm/pool.d/ (check the php version)
I suggest something like zzz-custom-user.conf so it’s loaded last. To that file add.

user = deployment
group = deployment
listen.owner = deployment
listen.group = deployment

Next reload everything, agian check php version.

sudo nginx -t && sudo service php7.2-fpm restart && sudo service nginx restart

Finally change the owner of the webfiles

sudo chown pi:pi /var/www/ -R

All done.

Leave a Reply

Your email address will not be published. Required fields are marked *