我刚刚在我的一台 Ubuntu Linux 20.04.6 服务器上将 nginx 更新到 1.25.4,现在无法启动。我收到的错误如下:
2024/03/07 12:46:28 [warn] 29836#29836: could not build optimal server_names_hash, you should increase either server_names_hash_max_size: 512 or server_names_hash_bucket_size: 64; ignoring server_names_hash_bucket_size
2024/03/07 12:46:28 [warn] 29836#29836: could not build optimal server_names_hash, you should increase either server_names_hash_max_size: 512 or server_names_hash_bucket_size: 64; ignoring server_names_hash_bucket_size
2024/03/07 12:46:28 [warn] 29836#29836: could not build optimal server_names_hash, you should increase either server_names_hash_max_size: 512 or server_names_hash_bucket_size: 64; ignoring server_names_hash_bucket_size
2024/03/07 12:46:28 [notice] 29836#29836: signal process started
2024/03/07 12:46:28 [error] 29836#29836: open() "/run/nginx.pid" failed (2: No such file or directory)
因此我打开 /etc/nginx/nginx.conf 并在块中修改了以下内容http
:
server_names_hash_max_size 1024;
server_names_hash_bucket_size 128;
然后我尝试再次启动 nginx,但出现以下错误:
2024/03/07 12:48:24 [notice] 30860#30860: signal process started
2024/03/07 12:48:24 [error] 30860#30860: open() "/run/nginx.pid" failed (2: No such file or directory)
我运行了它systemctl status nginx.service
并输出以下内容:
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2024-03-07 12:49:55 UTC; 10s ago
Docs: man:nginx(8)
Process: 31367 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Mar 07 12:49:55 Server-Name systemd[1]: Starting A high performance web server and a reverse proxy server...
Mar 07 12:49:55 Server-Name nginx[31367]: 2024/03/07 12:49:55 [emerg] 31367#31367: zero size shared memory zone "one"
Mar 07 12:49:55 Server-Name nginx[31367]: nginx: configuration file /etc/nginx/nginx.conf test failed
Mar 07 12:49:55 Server-Name systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Mar 07 12:49:55 Server-Name systemd[1]: nginx.service: Failed with result 'exit-code'.
Mar 07 12:49:55 Server-Name systemd[1]: Failed to start A high performance web server and a reverse proxy server.
我也尝试了journalctl -xe
更多细节,但似乎无法帮助我识别问题。以下是输出。
A start job for unit nginx.service has begun execution.
--
-- The job identifier is 3603.
Mar 07 12:49:55 Server-Name nginx[31367]: 2024/03/07 12:49:55 [emerg] 31367#31367: zero size shared memory zone "one"
Mar 07 12:49:55 Server-Name nginx[31367]: nginx: configuration file /etc/nginx/nginx.conf test failed
Mar 07 12:49:55 Server-Name systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
-- Subject: Unit process exited
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- An ExecStartPre= process belonging to unit nginx.service has exited.
--
-- The process' exit code is 'exited' and its exit status is 1.
Mar 07 12:49:55 Server-Name systemd[1]: nginx.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- The unit nginx.service has entered the 'failed' state with result 'exit-code'.
Mar 07 12:49:55 Server-Name systemd[1]: Failed to start A high performance web server and a reverse proxy server.
-- Subject: A start job for unit nginx.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit nginx.service has finished with a failure.
在我更新到 1.25.4 之前,nginx 服务器运行正常。知道发生了什么变化或是什么导致了这个问题吗?我还尝试清除 nginx,重新安装并重新配置它。问题仍然存在。我在其他服务器上没有遇到这个问题。
更新:我已删除所有虚拟主机,现在 nginx 已启动。将尝试逐个添加它们,直到失败,以便发现导致错误的原因:
2024/03/07 12:46:28 [error] 29836#29836: open() "/run/nginx.pid" failed (2: No such file or directory)
假设新版本与 nginx 的设置方式存在一些不兼容问题。奇怪的是,它没有指出问题出在哪个虚拟主机上。一旦我找到更多信息,我会再次更新。