본문 바로가기

카테고리 없음

[Linux] Job for nginx.service failed because a timeout was exceeded.

NGINX service를 시작하면 아래와 같은 에러 메세지로 시작이 안되는 경우가 있습니다.

# systemctl start nginx.service
Job for nginx.service failed because a timeout was exceeded.
See "systemctl status nginx.service" and "journalctl -xe" for details.

 

systemctl status nginx.service를 통해 에러 메세지를 확인합니다.

문제가 되는 에러는 아래와 같이 pid file 때문입니다.

Apr 16 08:54:03 localhost.localdomain systemd[1]: Starting The NGINX HTTP and reverse proxy server...
Apr 16 08:54:03 localhost.localdomain nginx[4607]: nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
Apr 16 08:54:03 localhost.localdomain nginx[4607]: nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Apr 16 08:54:03 localhost.localdomain systemd[1]: nginx.service: Can't open PID file /run/nginx.pid (yet?) after start: No such file or directory
Apr 16 08:55:33 localhost.localdomain systemd[1]: nginx.service: Start operation timed out. Terminating.
Apr 16 08:55:33 localhost.localdomain systemd[1]: nginx.service: Failed with result 'timeout'.
Apr 16 08:55:33 localhost.localdomain systemd[1]: Failed to start The NGINX HTTP and reverse proxy server.

 

/lib/systemd/system/nginx.service에는 PID file이 /run/nginx.pid에 정의되어 있습니다.

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install] WantedBy=multi-user.target

 

nginx.conf 파일에는 아래와 같이 PID file이 기본적으로 주석처리 되어 있습니다.

#pid logs/nginx.pid;

 

nginx.conf에 마찬가지로 PID file을 정의합니다.

pid /run/nginx.pid;