为什么nginx进程与用户nobody一起运行

Ans*_*yal 20 ubuntu nginx web-server apache-2.2

我试图将 nginx 设置为与我的一个 rails 应用程序一起运行,当查看 的输出时ps -e | grep nginx,我意识到 nginx 工作进程与用户 nobody 一起运行。

它们没有作为 www-data 运行的原因是什么?

Dre*_*ury 30

它们没有作为 www-data 运行的原因是什么?

是的。您很可能没有在 nginx config 中指定用户

用户指令:http : //nginx.org/en/docs/ngx_core_module.html#user

syntax: user user [group];
default:    
user nobody nobody;
context:    main
Run Code Online (Sandbox Code Playgroud)

如何以特定用户身份运行 nginx?

您可以在 nginx 配置中指定运行 nginx 的用户/组。

这是一个 nginx 配置的示例(注意用户指令):

pid                 /path/to/nginx.pid;
user                www-data www-data;
worker_processes    1;

events {
   worker_connections  1024; # usually 1024 is a good default
}

http {
   # more code goes here
}
Run Code Online (Sandbox Code Playgroud)

只需更新您的配置,然后重新加载或重新启动 nginx,您就可以开始使用了。

当然,您应该选择最适合您系统的用户,在 Debian/Ubuntu 中,默认情况下有一个 www-data,所以这是一个明智的选择。