리눅스

nginx: [emerg] bind() to 0.0.0.0:80 failed 해결 방법

nginx: [emerg] bind() to 0.0.0.0:80 failed 해결하기


Nginx 서비스를 시작하려고 할 때, 아래와 같이 문제가 발생할 수 있습니다.

root@myUbuntu:~# systemctl start nginx
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.

어떠한 문제로 인해 Nginx 서비스가 시작되지 못했다고 에러 메세지가 출력되었습니다.

자세한 원인을 알아보기 위해 systemctl status nginx.service 또는 journalctl -xe 를 입력하여 로그 메세지를 확인할 수 있습니다.

# journalctl -xe

로그를 살펴보면 다음과 같습니다.

-- Unit apt-daily.service has finished starting up.
--
-- The start-up result is RESULT.
6월 25 20:08:03 myUbuntu systemd[1]: Reloading.
6월 25 20:08:03 myUbuntu systemd[1]: Starting A high performance web server and a reverse proxy server...
-- Subject: Unit nginx.service has begun start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit nginx.service has begun starting up.
6월 25 20:08:06 myUbuntu nginx[112631]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
6월 25 20:08:06 myUbuntu nginx[112631]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
6월 25 20:08:06 myUbuntu nginx[112631]: nginx: [emerg] still could not bind()
6월 25 20:08:06 myUbuntu systemd[1]: nginx.service: Control process exited, code=exited status=1
6월 25 20:08:06 myUbuntu systemd[1]: nginx.service: Failed with result 'exit-code'.
6월 25 20:08:06 myUbuntu 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

주목할 부분은 nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 와 nginx: [emerg] bind() to [::]:80 failed (98: Address already in use) 부분입니다. 메세지에 나와있는 그대로 해당 주소가 이미 사용되고 있다는 의미입니다.

 

원인은 현재 다른 웹 서버 어플리케이션 또는 서비스가 80번 포트를 사용 중이기 때문에 발생하는 문제입니다.

해결 방법은 다음과 같습니다.

  • 80번 포트를 사용하는 서비스의 중지
  • 웹 서버를 80번 이외의 포트로 설정

 

아무래도 첫 번째 방법으로 해결하는 것이 좋을 것이라고 봅니다. 대부분의 웹 서버는 80번 포트를 사용하기 때문입니다.

현재 80번 포트를 사용하는 다른 서비스는 대부분 httpd일 것입니다. 기본적으로 httpd가 설치되는 경우가 많아 자칫 실수로 서비스가 실행 중인 상태가 될 수 있기 때문입니다.

 

아래 netstat 명령어로 80번 포트를 사용하는 프로세스를 다시 한 번 확인해보겠습니다.

root@jywork:~# netstat -anp | grep 80
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      680/systemd-resolve 
tcp        0      0 192.168.1.12:60650        192.168.1.101:80      ESTABLISHED 999/python3         
tcp        0      0 192.168.1.12:60646        192.168.1.101:80      ESTABLISHED 996/python3         
tcp        0      0 192.168.1.12:60648        192.168.1.101:80      ESTABLISHED 998/python3         
tcp        0      0 192.168.1.12:60642        192.168.1.101:80      CLOSE_WAIT  998/python3         
tcp6       0      0 :::80                   :::*                    LISTEN      5143/apache2        
udp     5376      0 192.168.1.12:53           0.0.0.0:*                           680/systemd-resolve 
unix  3      [ ]         STREAM     CONNECTED     380251   31266/snapd          
unix  3      [ ]         STREAM     CONNECTED     380283   1/init               /run/systemd/journal/stdout
unix  3      [ ]         STREAM     CONNECTED     14847    680/systemd-resolve  
unix  2      [ ]         DGRAM                    802811   1/init               
unix  2      [ ]         DGRAM                    14955    680/systemd-resolve  
unix  3      [ ]         STREAM     CONNECTED     278385   13800/upowerd        
unix  3      [ ]         STREAM     CONNECTED     278428   13800/upowerd        
unix  3      [ ]         STREAM     CONNECTED     16780    1/init               /run/systemd/journal/stdout
unix  2      [ ]         DGRAM                    89580    2790/acpid           
unix  3      [ ]         STREAM     CONNECTED     15658    680/systemd-resolve

위 결과에서 다음과 같이 80번 포트가 apache2 (httpd)로 인해 사용 중임을 알 수 있습니다. (나머지 부분은 grep으로 검색된 상관 없는 데이터들입니다.)

tcp6       0      0 :::80                   :::*                    LISTEN      5143/apache2

만약 apache가 아닌 nginx를 사용하고 싶다면, apache 서비스를 중지한 후 다시 nginx를 실행해야 합니다.

# service apache2 stop
# service nginx start
또는 아래와 같이 시도합니다.
# systemctl stop apache2
# systemctl start nginx

 

이제 서비스가 정상적으로 실행될 것입니다.

JooTC

안녕하세요. 테크놀로지에 관심이 많은 블로거입니다.

Recent Posts

Zalgo 텍스트와 이를 방지하는 방법

인터넷 커뮤니티 사이트에서 게시글이나 댓글에 간혹 장난을 목적으로 작성된 특이한 글자를 볼 수 있습니다. 위…

1개월 ago

리눅스 kill, killall 명령어 – 특정 프로세스 종료하기

리눅스 명령어 - kill, killall 리눅스 kill 명령어는 특정 프로세스를 종료해주는 명령어입니다. 백그라운드에서 실행되고 있는…

1개월 ago

JavaScript typeof null이 ‘object’인 이유

JavaScript는 역사가 긴 스크립트 프로그래밍 언어입니다. 세월이 흐르면서 많은 자바스크립트 표준이 만들어졌고, 현재는 많은 문법적…

1개월 ago

Mocha Error: Resolution method is overspecified. 해결 방법

NodeJS 테스트 프레임워크인 Mocha는 비동기 테스트를 지원합니다. 간혹 특정 테스트 스크립트를 작성하고 실행하면 아래와 같이…

1개월 ago

윈도우 11 설치 시 Microsoft 계정 로그인 없이 로컬 계정 만들기

언제부턴가 윈도우 11을 처음 설치할 때 마이크로소프트(Microsoft) 계정 로그인을 강제로 요구하게 되었습니다. 물론 마이크로소프트 계정이…

6개월 ago

에어팟 프로 2 케이스 스피커 소리를 완전히 끄는 방법

애플 에어팟 프로 2 (AirPods Pro 2) 케이스에는 스피커가 내장되어 있습니다. 그런데 간혹 아무 것도…

9개월 ago