Skip to content

장고 과제4 nginx stop 혹은 restart 시 오류 관련 #680

@xxnpark

Description

@xxnpark

요약 & 상황

과제 4를 진행하면서 nginx.config 파일 수정 이후 nginx를 재시작하려고 할 때, 80번 포트가 사용중이라며 98: Address already in use 에러가 계속해서 발생하고 있습니다.

문제 내용

우선 sudo service nginx restart를 실행하면 다음과 같이 에러가 발생했습니다.

(venv) [ec2-user@ip-172-31-23-78 waffle_backend]$ sudo service nginx restart
Redirecting to /bin/systemctl restart nginx.service
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

에러 내용을 확인해보았더니 포트가 이미 사용중일때 뜨는 98번 에러가 발생함을 확인할 수 있었습니다.

(venv) [ec2-user@ip-172-31-23-78 waffle_backend]$ systemctl status nginx.service
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since 일 2021-11-14 05:20:55 UTC; 7s ago
  Process: 18626 ExecStart=/usr/sbin/nginx (code=exited, status=1/FAILURE)
  Process: 18622 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 18621 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)

11월 14 05:20:52 ip-172-31-23-78.us-east-2.compute.internal nginx[18626]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address al...use)
11월 14 05:20:53 ip-172-31-23-78.us-east-2.compute.internal nginx[18626]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address al...use)
11월 14 05:20:53 ip-172-31-23-78.us-east-2.compute.internal nginx[18626]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address al...use)
11월 14 05:20:54 ip-172-31-23-78.us-east-2.compute.internal nginx[18626]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address al...use)
11월 14 05:20:54 ip-172-31-23-78.us-east-2.compute.internal nginx[18626]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address al...use)
11월 14 05:20:55 ip-172-31-23-78.us-east-2.compute.internal nginx[18626]: nginx: [emerg] still could not bind()
11월 14 05:20:55 ip-172-31-23-78.us-east-2.compute.internal systemd[1]: nginx.service: control process exited, code=exited status=1
11월 14 05:20:55 ip-172-31-23-78.us-east-2.compute.internal systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
11월 14 05:20:55 ip-172-31-23-78.us-east-2.compute.internal systemd[1]: Unit nginx.service entered failed state.
11월 14 05:20:55 ip-172-31-23-78.us-east-2.compute.internal systemd[1]: nginx.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

그래서 80번 포트의 사용을 검색해보았더니 nginx worker process가 실행중인 것 같았는데, 그러면 어떻게 nginx를 재시작할 수 있는지 궁금합니다.

(venv) [ec2-user@ip-172-31-23-78 waffle_backend]$ netstat -anp | grep 80
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      16780/nginx: worker
udp6       0      0 fe80::49e:a7ff:fe06:546 :::*                                -
unix  2      [ ]         DGRAM                    80200    -
unix  3      [ ]         STREAM     CONNECTED     62257    16780/nginx: worker
unix  3      [ ]         STREAM     CONNECTED     12680    -                    /run/systemd/journal/stdout

또한 nginx를 종료하고 다시 시작하려고 sudo nginx -s stop을 실행해본 결과, nginx.pid 가 발견되지 않는 문제가 있었습니다.

(venv) [ec2-user@ip-172-31-23-78 waffle_backend]$ sudo nginx -s stop
nginx: [error] open() "/run/nginx.pid" failed (2: No such file or directory)

링크와 기타 사이트를 검색해본 결과 ps -ef | grep nginx을 통해 실행중인 nginx 프로세스를 직접 찾아 kill하거나 pkill nginx로 처리한 뒤 실행하라고 하였는데, 이 방법으로는 nginx를 멈추고 다시 시작하는 것이 가능했습니다. 위의 80번 포트 사용 문제나 pid 파일 미발견 문제는 어떻게 처리해야할까요?

Metadata

Metadata

Assignees

No one assigned

    Labels

    DjangoDjango 관련question질문으로 사용될 이슈

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions