Failed to reload nginx.service: Interactive authentication required

放肆的年华 提交于 2020-12-12 05:43:32

问题


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,
    ]);
}

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


回答1:


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.

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

  • 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.



来源:https://stackoverflow.com/questions/51500748/failed-to-reload-nginx-service-interactive-authentication-required

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!