私のnginxは/usr/sbin/nginx -c /etc/nginx/nginx.conf
コマンドラインでうまく起動しますが、起動しようとすると次のようになります。
# systemctl start nginx
その後、タイムアウトするまで停止します。
私のシステムデバイスは次のとおりです。
[Unit]
Description=A high performance web server and a reverse proxy server
Documentation=man:nginx(8)
After=network.target
[Service]
Type=forking
PIDFile=/var/run/nginx/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
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /var/run/nginx/nginx.pid
TimeoutStopSec=5
KillMode=mixed
[Install]
WantedBy=multi-user.target
以下はnginxを起動しようとしています。
root@efk:~# systemctl start nginx
Job for nginx.service failed because a timeout was exceeded.
See "systemctl status nginx.service" and "journalctl -xe" for details.
root@efk:~# 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: timeout) since Mon 2021-10-04 00:32:44 CEST; 1min 25s ago
Docs: man:nginx(8)
Process: 14413 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 14403 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 466 (code=exited, status=0/SUCCESS)
Oct 04 00:31:14 efk systemd[1]: Starting A high performance web server and a reverse proxy server...
Oct 04 00:31:14 efk systemd[1]: nginx.service: Can't open PID file /var/run/nginx/nginx.pid (yet?) after start: No such file or dir
Oct 04 00:32:44 efk systemd[1]: nginx.service: Start operation timed out. Terminating.
Oct 04 00:32:44 efk systemd[1]: nginx.service: Killing process 14414 (nginx) with signal SIGKILL.
Oct 04 00:32:44 efk systemd[1]: nginx.service: Killing process 14416 (nginx) with signal SIGKILL.
Oct 04 00:32:44 efk systemd[1]: nginx.service: Killing process 14417 (nginx) with signal SIGKILL.
Oct 04 00:32:44 efk systemd[1]: nginx.service: Failed with result 'timeout'.
Oct 04 00:32:44 efk systemd[1]: Failed to start A high performance web server and a reverse proxy server.
root@efk:~# journalctl -xe
Oct 04 00:32:44 efk systemd[1]: nginx.service: Start operation timed out. Terminating.
Oct 04 00:32:44 efk systemd[1]: nginx.service: Killing process 14414 (nginx) with signal SIGKILL.
Oct 04 00:32:44 efk systemd[1]: nginx.service: Killing process 14416 (nginx) with signal SIGKILL.
Oct 04 00:32:44 efk systemd[1]: nginx.service: Killing process 14417 (nginx) with signal SIGKILL.
Oct 04 00:32:44 efk systemd[1]: nginx.service: Failed with result 'timeout'.
Oct 04 00:32:44 efk systemd[1]: Failed to start A high performance web server and a reverse proxy server.
-- Subject: Unit nginx.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit nginx.service has failed.
--
-- The result is RESULT.
しかし始めたら:
# /usr/sbin/nginx -c /etc/nginx/nginx.conf
良い結果。
nginxは次のようになります
root@efk:~# /usr/sbin/nginx -V
nginx version: nginx/1.21.3 (nginx-quic)
built by gcc 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
built with OpenSSL 1.1.1 (compatible; BoringSSL) (running with BoringSSL)
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/run/lock/subsys/nginx --build=nginx-quic --with-debug --add-module=../njs/nginx --user=www-data --group=www-data --with-threads --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_v3_module --with-http_quic_module --with-stream_quic_module --with-http_realip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_slice_module --with-http_stub_status_module --without-select_module --without-poll_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-openssl=/home/mtodorov/build/boringssl --with-cc-opt='-g -O2 -fPIE -fstack-protector-all -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -I /home/mtodorov/build/boringssl/.openssl/include/' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -L /home/mtodorov/build/boringssl/.openssl/lib/'
root@efk:~#
それでは、/var/run/nginx/nginx.pid パスがコンパイルされますが、systemd デバイスで実行するときにサーバーがなぜそれを見つけることができないのかわかりませんか?
どんなアイデアがありますか?
マービン
答え1
質問は愚かです。コンパイルされた構成は使用されますが、nginxは使用されませ/var/run/nginx.pid
ん/var/run/nginx/nginx.pid
(apache2とは異なります)。
nginx.serviceユニットでこれを変更すると問題が解決し、systemctl start nginx
ディレクティブがスムーズに動作します。
マービン
答え2
ChromeOSでnginxを起動する際に同様の問題が発生しました。修正はほぼ同じですが、/etc/init.d/nginx
ちょうど。PID=/run/nginx.pid
PID=/run/nginx/nginx.pid
systemctl start nginx
変更後に作業してください。 aptがsystemdサービスを追加するのではなく、init.dにこれを置く理由はわかりませんが、うまくいきます。