내 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에 이것을 넣는 이유는 확실하지 않지만 작동합니다.