我最近将我的 Ubuntu 服务器升级到 16.04 版本。从那时起,我无法启动 nginx 服务。
结果service nginx restart
:
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
我的系统日志显示(cat /var/log/syslog
):
May 20 17:03:53: Stopped A high performance web server and a reverse proxy server.
May 20 17:03:53: Starting A high performance web server and a reverse proxy server...
May 20 17:03:53: nginx.service: Failed at step EXEC spawning /usr/sbin/nginx: No such file or directory
May 20 17:03:53: nginx.service: Control process exited, code=exited status=203
May 20 17:03:53: Failed to start A high performance web server and a reverse proxy server.
May 20 17:03:53: nginx.service: Unit entered failed state.
May 20 17:03:53: nginx.service: Failed with result 'exit-code'.
结果cat /lib/systemd/system/nginx.service
:
# Stop dance for nginx
# =======================
#
# ExecStop sends SIGSTOP (graceful stop) to the nginx process.
# If, after 5s (--retry QUIT/5) nginx is still running, systemd takes control
# and sends SIGTERM (fast shutdown) to the main process.
# After another 5s (TimeoutStopSec=5), and if nginx is alive, systemd sends
# SIGKILL to all the remaining processes in the process group (KillMode=mixed).
#
# nginx signals reference doc:
# http://nginx.org/en/docs/control.html
#
[Unit]
Description=A high performance web server and a reverse proxy server
After=network.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
# Use TERM instead of QUIT to prevent Nginx from leaving stale Unix socket and failing the next start (https://trac.nginx.org/nginx/ticket/753)
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry TERM/5 --pidfile /run/nginx.pid
# Give Passenger a chance to clean up before being killed by systemd.
ExecStop=/bin/sleep 1
TimeoutStopSec=5
KillMode=mixed
[Install]
WantedBy=multi-user.target
确实没有文件/usr/sbin/nginx
,所以我尝试了apt install nginx
,但结果如下:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
nginx : Depends: nginx-core (>= 1.10.0-0ubuntu0.16.04.4) but it is not going to be installed or
nginx-full (>= 1.10.0-0ubuntu0.16.04.4) but it is not going to be installed or
nginx-light (>= 1.10.0-0ubuntu0.16.04.4) but it is not going to be installed or
nginx-extras (>= 1.10.0-0ubuntu0.16.04.4) but it is not going to be installed
Depends: nginx-core (< 1.10.0-0ubuntu0.16.04.4.1~) but it is not going to be installed or
nginx-full (< 1.10.0-0ubuntu0.16.04.4.1~) but it is not going to be installed or
nginx-light (< 1.10.0-0ubuntu0.16.04.4.1~) but it is not going to be installed or
nginx-extras (< 1.10.0-0ubuntu0.16.04.4.1~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
作为一个新手,我在这个混乱中很迷失,我真的需要一点帮助。
非常感谢您的宝贵时间。
更新 1:
结果apt-cache policy nginx
:
nginx:
Installed: 1.12.0-1+xenial1
Candidate: 1.12.0-1+xenial1
Version table:
*** 1.12.0-1+xenial1 500
500 http://ppa.launchpad.net/nginx/stable/ubuntu xenial/main amd64 Packages
500 http://ppa.launchpad.net/nginx/stable/ubuntu xenial/main i386 Packages
100 /home/var/lib/dpkg/status
1.10.0-0ubuntu0.16.04.4 500
500 http://ubuntu.mirrors.ovh.net/ftp.ubuntu.com/ubuntu xenial-updates/main amd64 Packages
500 http://ubuntu.mirrors.ovh.net/ftp.ubuntu.com/ubuntu xenial-updates/main i386 Packages
500 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages
500 http://security.ubuntu.com/ubuntu xenial-security/main i386 Packages
1.9.15-0ubuntu1 500
500 http://ubuntu.mirrors.ovh.net/ftp.ubuntu.com/ubuntu xenial/main amd64 Packages
500 http://ubuntu.mirrors.ovh.net/ftp.ubuntu.com/ubuntu xenial/main i386 Packages
答案1
因此,您遇到了两个相互冲突的问题,并且似乎导致 nginx 二进制文件以某种方式消失:Xenial 存储库版本和 NGINX PPA。作为两者的维护者,请允许我解释一下这种冲突。
在 Xenial 中,我们在发布后立即发布了 1.10.0 作为更新。此更新将我们推向了“稳定”分支,但尚未构建和提供可动态加载的模块。这是由于时间原因,也是测试期间出现的构建冲突。我们最终在 Zesty 中实现了动态模块支持。
在 PPA 中,我们始终直接从 Debian 克隆。这意味着,我们始终拥有 Debian 的“动态模块”支持,这与 Xenial 软件包相冲突,并导致一些安装和升级冲突。
这里有一个小冲突 - 您不能混合搭配nginx-core
(这是 Ubuntu 中安装的软件包的默认风格nginx
)和 PPA,因为有时它会导致某些东西消失。那么,这里的问题是,我们需要删除现有的 Ubuntu 软件包,然后仅从 PPA 安装。
要解决此问题,您首先需要备份要为网站保留的 nginx 配置。也就是说,将 /etc/nginx/sites-available/ 目录复制到其他地方(即使在用户的主目录中也可以,我们只需要网站配置的副本)。此外,我们需要备份您的网站数据,因此也将其复制到其他地方(不要在标准文档根目录中,以免弄乱)。
复制完成后,您必须删除现有的 nginx 包。可以使用以下命令完成此操作:
sudo apt-get remove nginx nginx-common nginx-doc nginx-core nginx-full nginx-extras nginx-light
完成后,sudo apt-get update
再次运行以确保我们拥有最新的版本编号。
然后,nginx
从 PPA 安装 -sudo apt-get install nginx nginx-full nginx-common
应该这样做。
您不再会收到启动失败错误。请确保您的站点配置仍然有效,并且没有被覆盖。如果被覆盖,请从我们之前备份的站点配置和站点数据中恢复。否则,您已全部设置完毕。