Nginx fresh install configuration

nginx

I've just installed nginx on my server; now I can see with

ps aux | grep nginx

that it is in execution with my user (is this correct or should it run with root?);
anyway I'm not able to do anything with it, cannot stop it for example since

nginx -s stop

outputs:

nginx: [alert] could not open error log file: open() 
"/var/log/nginx/error.log" failed (13: Permission denied)
2017/05/02 04:03:34 [warn] 2482#2482: the "user" directive makes sense 
only if the master process runs with super-user privileges, ignored in 
/etc/nginx/nginx.conf:2
2017/05/02 04:03:34 [notice] 2482#2482: signal process started
2017/05/02 04:03:34 [error] 2482#2482: open() "/var/run/nginx.pid" 
failed (2: No such file or directory)

I've googling around about these warnings and errors, but I can't really understand them; can someone please explain:

  • the meaning of the log file warning and the .pid file error
  • if nginx should run with my user or with root (or something else)

UPDATE:

I'm using ubuntu server 16.04 (xenial) and I've installed nginx adding

deb http://nginx.org/packages/ubuntu/ xenial nginx

to sources.list and then

sudo apt-get install nginx

UPDATE 2

Trying to stop nginx with "sudo" still leads to error:

nginx: [error] open() "/var/run/nginx.pid" failed (2: No such file or directory)

anyway I am also confused about why

ps aux | grep nginx

shows the process running under my user (but it is not possible to kill it using the PID, and every time I run the command the PID is different)

UPDATE 3

running

nginx -t

outputs:

nginx: [alert] could not open error log file: open() 
"/var/log/nginx/error.log" failed (13: Permission denied)
2017/05/02 15:32:53 [warn] 8535#8535: the "user" directive makes sense 
only if the master process runs with super-user privileges, ignored in 
/etc/nginx/nginx.conf:2
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2017/05/02 15:32:53 [emerg] 8535#8535: open() "/var/run/nginx.pid" 
failed (13: Permission denied)
nginx: configuration file /etc/nginx/nginx.conf test failed

Best Answer

You need to have root privileges when you want to start or stop the nginx daemon. Running the commands as normal user won't work.

This is pretty much standard for all daemons in Linux.