无法重新加载nginx.service:需要交互式身份验证

时间:2018-07-24 14:07:49

标签: php symfony nginx command-line

我正在使用symfony 3进行项目, 该项目在Nginx服务器上运行 我正在尝试使用以下命令重新加载配置文件: 控制器中的“ systemctl reload nginx”。

/**
* @Route("/testReloadConfig")
*/
public function testReloadConfigAction(Request $request){

    $output = [];
    $result = null;

    $cmd = 'systemctl reload nginx 2>&1';

    exec($cmd, $output, $result);

    return new JsonResponse([
        'result' => $result,
        'output' => $output,
    ]);
}

响应:
    {“结果”:1,“输出”:[“无法重新加载nginx.service:需要交互式身份验证。”,“请参阅系统日志和\ u0027systemctl状态nginx.service \ u0027了解详细信息。”]}

1 个答案:

答案 0 :(得分:1)

很可能nginx不能与用户root一起运行,而这正是您需要使用systemctl的原因。因此,您应该使用sudo执行命令。

现在,有多种方法可以使用具有root特权的Web服务器运行命令:

  • 出于明显的安全原因,强烈建议用户<{1}}运行nginx
  • 仅以described here的形式将此特定命令添加到root,以便以sudoers特权运行该命令而没有任何密码提示
  • described here的身份通过root传递您的root密码
  • 写一个功能有限的bash脚本,例如described here

但是,当然,您可能会在寻找其他东西。

相关问题