nginx服务器无法使用服务nginx start

时间:2016-07-01 14:01:57

标签: nginx centos

 this is my error.log
    016/07/01 07:38:17 [emerg] 30759#0:getpwnam(" nginx")在/etc/nginx/nginx.conf:5失败     2016/07/01 07:48:02 [emerg] 30806#0:getpwnam(" nginx")在/etc/nginx/nginx.conf:5失败     2016/07/01 07:48:44 [emerg] 30832#0:getpwnam(" nginx")在/etc/nginx/nginx.conf:5失败     2016/07/01 08:07:36 [emerg] 30913#0:getpwnam(" nginx")在/etc/nginx/nginx.conf:5失败     2016/07/01 08:07:44 [emerg] 30939#0:getpwnam(" nginx")在/etc/nginx/nginx.conf:5失败     2016/07/01 08:07:49 [emerg] 30964#0:getpwnam(" nginx")在/etc/nginx/nginx.conf:5失败     2016/07/01 08:13:54 [emerg] 31138#0:getpwnam(" nginx")在/etc/nginx/nginx.conf:5失败     2016/07/01 09:52:49 [emerg] 31735#0:getpwnam(" nginx")失败     

    #and this is my nginx.conf

worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    include /etc/nginx/conf.d/*.conf;
    server {
    listen       80 default_server;
    listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;
        include /etc/nginx/default.d/*.conf;
        location / {
        }
    error_page 404 /404.html;
            location = /40x.html {
        }

    error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
}

3 个答案:

答案 0 :(得分:4)

如果您从源代码编译Nginx,则可能在编译时指定了用户和组标志。

如果是这种情况,您需要确保在尝试启动Nginx时用户确实存在。

如何修复getpwnam(“nginx”)失败

修复此问题很容易,只需通过发出以下命令创建指定的用户(在本例中为'nginx'):

useradd nginx

如果您希望创建没有主目录的用户,只需添加--no-create-homeflag,如下:

useradd --no-create-home nginx

答案 1 :(得分:0)

你的nginx.conf缺少用户指令http://nginx.org/en/docs/ngx_core_module.html#user

如果这不起作用命令“journalctl -xe”输出什么?

答案 2 :(得分:0)

最后我自己找到了解决方案。

我使用nginx -t表示我的代码中没有任何语法错误。

然后我用了

user nobody; // in my nginx.conf

这解决了我的问题