使用命令“nginx”、“service start nginx”和“systemctl nginx start”启动nginx有什么区别?

Mah*_*Ali 5 nginx nginx-location nginx-reverse-proxy

我注意到,当我使用 ubuntu 命令“nginx”启动 nginx 时,我会执行 systemctl status nginx。它表明 systemctl 被禁用。更重要的是,如果我首先使用命令 systemctl start nginx 启动 nginx,然后尝试使用命令 nginx 启动 nginx,它会检查端口的可用性,然后说 nginx: [emerg] 仍然无法绑定()。所以我认为他们的目的一定是不同的。当我使用命令 nginx strt nginx 时,停止 nginx 的唯一方法是强制使用killlall nginx或kill -9(进程ID)或清除端口。所以我很确定它们之间存在一些差异。

小智 6

您提供的示例之间的区别在于进程的启动方式。

运行该命令nginx将启动应用程序并等待您的用户操作将其停止。

或命令几乎是相同的,并且运行systemctl或将在后台运行 Nginx 守护进程启动一个服务。serviceservice nginx startsystemctl start nginx

您还可以使用它来执行service nginx restartsystemctl restart nginx来重新启动服务,甚至使用service nginx reload/systemctl reload nginx来重新加载配置,而无需完全停止 Nginx 服务器。

之所以不能同时执行这两项操作,nginxsystemctl start nginx因为 nginx 配置已经侦听端口 80,并且您无法同时侦听单个 IP 地址上的同一端口。

您还可以通过运行强制 nginx 服务在启动时启动,systemctl enable nginx这就是您systemctl status nginx返回“禁用”的原因。

希望这是有道理的。