UID for nginx to access staticfiles, run nginx with a user without being logged in as that user

I was following a tutorial where a linux user is created with useradd instead of adduser. My question is if I need to be logged in as the user with permissions on the staticfiles folders when running ‘service nginx start’ and if this is how the uid of nginx is set to match the uid required in the permissions of the folders.

I’m asking because in the tutorial you don’t log in with the user, you just create it, set all the permissions to it and make this the user in the supervisorctl config files for gunicorn. However it seems like this is a reason why nginx static files and logs aren’t working because ‘service nginx start’ is run with whatever user you’re doing the tutorial with not this user with the permissions.

Does every one run nginx with ‘service nginx start’ or is it also started from supervisorctl or another service where you specify the user to run it?

I’ve previously got around this issue by running nginx from my local user, however with useradd, it seem it’s not the same type of user as adduser (Useradd vs Adduser: What's the Difference?). So before troubleshooting the user or creating a new user the other way with adduser I just wanted to check the standard way to make the nginx uid match the folder permission and if I can do it without logging in as that user. Thanks

Edit: I have also looked at the permissions section of the nginx pitfalls:

However it doesn’t go into much detail about permissions, is just said don’t use 777.

Well, this isn’t by far a Django related question, but I will tried to help.

When you create a “user” in a *nix type system (Linux, BSD, etc) that doesn’t mean a person will operate the user. Users can be abstract entities that only are used by process of the system.
If you type the command “top” in your shell you will see that most of the process that are running aren’t operated by the user you login in the system, in fact most of the process are owned by root, that is a user that maybe you will never login as. This answer dig deeper in this concept.
Al that said you should carefully read about users and permissions in Linux systems, there ins plenty of information in the web.
Once you understand permission you will notice that assign 777 permissions mean that every user can change a file, therefore a normal user can change your process. That is a bad practice and can derivative in several security hole.
I hope the information helps.

Your nginx.conf file defines what UID the nginx server runs as. You need to start nginx as root because it typically opens up two protected ports - 80 and 443. But nginx then switches to the UID as defined.

See Core functionality

Thanks both for the reply. I got it working with user in the nginx.conf as:
user www-data;

Then setting permissions in the static folder with:
chown -R www-data:www-data .

Then restart nginx:
service nginx restart

This page was also helpful: