无法重新加载nginx.service:需要交互式身份验证 [英] Failed to reload nginx.service: Interactive authentication required

查看:28
本文介绍了无法重新加载nginx.service:需要交互式身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working on project using symfony 3, the project run on nginx server and i am trying to reload the configuration files with the following command: "systemctl reload nginx" from the controller.

/**
* @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了解详细信息."]}

The response:
{"result":1,"output":["Failed to reload nginx.service: Interactive authentication required.","See system logs and \u0027systemctl status nginx.service\u0027 for details."]}

推荐答案

nginx 可能无法与用户 root 一起运行,而这正是使用 systemctl .因此,您应该使用 sudo 执行命令.

Most probably nginx doesn't run with user root which is what you need to use systemctl. Therefore you should execute your command using sudo.

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

Now there are different ways of running a command from web-server with root privileges:

  • 使用强烈劝阻的用户 root 运行 nginx ,出于明显的安全原因
  • 仅将此特定命令作为在此处描述
  • 写一个功能有限的bash脚本,如此处所述
  • Run nginx with user root which is highly discouraged for obvious security reasons
  • Add only this specific command to sudoers as described here in order to run it with root privileges without any password prompt
  • Pass your root password through echo as described here
  • Write a bash script with limited functions as described here

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

But of course you might find something else searching on for it.

这篇关于无法重新加载nginx.service:需要交互式身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆