나는 두 가지 질문이 있습니다 어떻게 Nginx conf를 제대로보고 다시로드합니까?
- 는 차이가 있습니까 : 변화가 conf의 파일 (
nginx -t
)을 테스트 무엇 Nginx에 conf의 파일을 볼 수있는 간단한 방법이고에nginx -s reload
및 pkill -HUP -F nginx.pid
, 그리고 통과되는 경우 Nginx를 다시로드하십시오.runit
또는 수퍼바이저 같은 프로세스 관리자로 처리 할 수 있습니까?
나는 두 가지 질문이 있습니다 어떻게 Nginx conf를 제대로보고 다시로드합니까?
nginx -t
)을 테스트 무엇 Nginx에 conf의 파일을 볼 수있는 간단한 방법이고에 nginx -s reload
및pkill -HUP -F nginx.pid
, 그리고 통과되는 경우 Nginx를 다시로드하십시오. runit
또는 수퍼바이저 같은 프로세스 관리자로 처리 할 수 있습니까?적어도 유닉스, "새로 고침"작용 HUP
신호 모두 선언 코드 src/os/unix/ngx_process.c
에
ngx_signal_t signals[] = {
{ ngx_signal_value(NGX_RECONFIGURE_SIGNAL),
"SIG" ngx_value(NGX_RECONFIGURE_SIGNAL),
"reload",
ngx_signal_handler },
한 덕분으로 처리된다. ngx_signal_handler()
에서 같은 comnmon 코드
case ngx_signal_value(NGX_RECONFIGURE_SIGNAL):
ngx_reconfigure = 1;
action = ", reconfiguring";
break;
는 공통의 재구성을위한 준비가 실행됩니다.
파일이 수정되었을 때 작업을 실행하려면 crontab을 만들고 확인주기를 결정하거나 inotifywait을 사용할 수 있습니다.
이 nginx -t
에 오류가있는 경우, 결정 떠들썩한 파일에서 리턴 코드를 확인하려면, $?
nginx -t
if [ $? -eq 0 ] then;
nginx -s reload
fi
참고 : 당신은 또한 service nginx reload
이
( here 리턴 코드 검사 예를 참조)를 사용할 수 있습니다실제로 나는 보통'service nginx reload'를 사용합니다. – rednaw
@rednaw님께 감사드립니다. –
오타가 있습니다. 마지막 코드 블록에서'linux -t' 대신'nginx -t '여야합니다. (바보 같은 "편집에 필요한 6 자"규칙 때문에 변경할 수 없음) – matlehmann
#!/bin/bash
# NGINX WATCH DAEMON
#
# Author: Devonte
#
# Place file in root of nginx folder: /etc/nginx
# This will test your nginx config on any change and
# if there are no problems it will reload your configuration
# USAGE: sh nginx-watch.sh
# Set NGINX directory
# tar command already has the leading/
dir='etc/nginx'
# Get initial checksum values
checksum_initial=$(tar --strip-components=2 -C/-cf - $dir | md5sum | awk '{print $1}')
checksum_now=$checksum_initial
# Start nginx
nginx
# Daemon that checks the md5 sum of the directory
# ff the sums are different (a file changed/added/deleted)
# the nginx configuration is tested and reloaded on success
while true
do
checksum_now=$(tar --strip-components=2 -C/-cf - $dir | md5sum | awk '{print $1}')
if [ $checksum_initial != $checksum_now ]; then
echo '[ NGINX ] A configuration file changed. Reloading...'
nginx -t && nginx -s reload;
fi
checksum_initial=$checksum_now
sleep 2
done
'-F' 또는'-f'입니까? (내'pkill'에'-F'가 없습니다) –
적어도 우분투 13.04에서는'-F' o입니다 r'- pidfile'. – velo9