无法重新加载nginx.service:需要交互式身份验证 [英] Failed to reload nginx.service: Interactive authentication required
问题描述
我正在使用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:
- Run
nginx
with userroot
which is highly discouraged for obvious security reasons - Add only this specific command to
sudoers
as described here in order to run it withroot
privileges without any password prompt - Pass your
root
password throughecho
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屋!