11

I am trying to run nginx as the current user (=ayush). But I get the following error on setting the user directive:

Dec 11 22:26:13 manjaro nginx[17194]: 2015/12/11 22:26:13 [emerg] 17194#0: getgrnam("ayush") failed in /etc/nginx/nginx.conf:1
Dec 11 22:26:13 manjaro systemd[1]: nginx.service: Control process exited, code=exited status=1

my nginx.conf :

user ayush;
worker_processes 1;

error_log  /var/log/nginx/error.log;
events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #access_log  logs/access.log  main;

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;


        location / {
            root   /code/server;
            autoindex on;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
    }
}

also:

ayush@manjaro ~> whoami
ayush
Ayush
  • 245
  • 1
  • 3
  • 10

3 Answers3

18

The user directive takes two parameters, your user and your group name. If you do not specify a group name, it assumes it's the same as your username.

The error is because the group name ayush does not exist.

See this document for details.

Richard Smith
  • 11,859
  • 2
  • 18
  • 26
7

In MacOS group name is a number (Use the command: id -g -n $whoami or open MacOS Setting -> Users and Groups -> Right click on your account and choose Advanced Options). But nginx only work if I specify the group name as 'staff'.

My nginx config:

user MyUserName staff; ...

bigbangvn
  • 71
  • 1
  • 3
1

You need specify two parameters for user directive, your user and your group name. If no group name if specified, it will assume it be same as user, which seems to be the problem in your case i.e. your group name is not same as user(ayush).

To see your username, execute following command:

whoami

To see your group name, execute following command:

id -g -n $whoami