비전공자도 이해할 수 있는 Nginx 입문/실전
🧑🏻🏫
개발을 하다보면 에러를 디버깅하고 해결하는 데에만 대부분의 시간을 쓴다. 따라서 어떤 기술을 익힐 때 반드시 에러를 디버깅 할 수 있는 방법을 정리해두어야 한다.
✅ 에러 상황
/etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/htlm;
index hello.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
위 코드에서 /usr/share/nginx/html이라고 작성해야 하는 걸, 실수로 /usr/share/nginx/htlm로 작성했다고 가정해보자. 이 상황에서 에러를 어떻게 디버깅해야 하는 지 알아보자.
✅ Nginx 에러 디버깅 방법
- Nginx가 정상적으로 실행되고 있는 지 체크
$ sudo systemctl status nginx
- 문법 에러 체크하기
$ sudo nginx -t
- 로그 파일 실시간으로 확인하기
# 제대로 요청이 들어오고 있는 지 확인
$ sudo tail -f /var/log/nginx/access.log
# 에러 메시지 확인
$ sudo tail -f /var/log/nginx/error.log