웹서버에 띄워놓은 페이지를 탐색하던 중 어쩌다 발견했는데
이상하게 nginx가 아닌 apache에서 구동되고 있었다

 

혹시나 해서 서비스 실행 상태를 확인해 보니 웬걸

언제부터인지 nginx 서비스가 구동에 실패했단다

더보기

pi@raspberrypi:~ $ systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sat 2023-05-13 08:16:49 KST; 1 day 2h ago
       Docs: man:nginx(8)
    Process: 563 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 613 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
        CPU: 161ms

May 13 08:16:48 raspberrypi nginx[613]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
May 13 08:16:48 raspberrypi nginx[613]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
May 13 08:16:48 raspberrypi nginx[613]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
May 13 08:16:48 raspberrypi nginx[613]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
May 13 08:16:49 raspberrypi nginx[613]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
May 13 08:16:49 raspberrypi nginx[613]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
May 13 08:16:49 raspberrypi nginx[613]: nginx: [emerg] still could not bind()
May 13 08:16:49 raspberrypi systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
May 13 08:16:49 raspberrypi systemd[1]: nginx.service: Failed with result 'exit-code'.
May 13 08:16:49 raspberrypi systemd[1]: Failed to start A high performance web server and a reverse proxy server.

 

대신 apache2란 놈이 nginx를 밀어내고 그 자릴 꿰차고 있다
이런 게 바로 굴러온 돌이 박힌 돌 뭐시기

더보기

pi@raspberrypi:~ $ systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2023-05-13 08:16:47 KST; 1 day 2h ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 561 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
    Process: 6990 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS)
   Main PID: 617 (apache2)
      Tasks: 11 (limit: 3933)
        CPU: 23.719s
     CGroup: /system.slice/apache2.service
             ├─  617 /usr/sbin/apache2 -k start
             ├─ 7017 /usr/sbin/apache2 -k start
             ├─ 7018 /usr/sbin/apache2 -k start
             ├─ 7019 /usr/sbin/apache2 -k start
             ├─ 7021 /usr/sbin/apache2 -k start
             ├─ 8929 /usr/sbin/apache2 -k start
             ├─ 8930 /usr/sbin/apache2 -k start
             ├─ 8931 /usr/sbin/apache2 -k start
             ├─10467 /usr/sbin/apache2 -k start
             ├─10468 /usr/sbin/apache2 -k start
             └─10978 /usr/sbin/apache2 -k start

May 14 09:50:12 raspberrypi sudo[11643]: pam_unix(sudo:session): session closed for user root
May 14 09:50:12 raspberrypi sudo[11654]: www-data : PWD=/var/www/html/admin ; USER=root ; COMMAND=/usr/local/bin/pihole -a setdns 8.8.8.8,8.>
May 14 09:50:12 raspberrypi sudo[11654]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=33)
May 14 09:50:12 raspberrypi sudo[11654]: pam_unix(sudo:session): session closed for user root
May 14 10:19:32 raspberrypi sudo[11928]: www-data : PWD=/var/www/html/admin/scripts/pi-hole/php ; USER=root ; COMMAND=/usr/local/bin/pihole >
May 14 10:19:32 raspberrypi sudo[11928]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=33)
May 14 10:19:32 raspberrypi sudo[11928]: pam_unix(sudo:session): session closed for user root
May 14 10:19:32 raspberrypi sudo[11941]: www-data : PWD=/var/www/html/admin/scripts/pi-hole/php ; USER=root ; COMMAND=/usr/local/bin/pihole >
May 14 10:19:32 raspberrypi sudo[11941]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=33)
May 14 10:19:32 raspberrypi sudo[11941]: pam_unix(sudo:session): session closed for user root

 

재부팅 후에 다시 확인해 봐도 마찬가지

 

가벼운 게 장점이라는 nginx조차 자식 프로세스가 4개씩이나 필요한지 의문인 와중에
apache2는 실행 중인 프로세스 숫자만 봐도 후덜덜하니
그냥 이대로 쓰기에는 신경이 너무 거슬린다

 

거기다 보안에도 문제가 있어서
따로 설정하지 않은 폴더에 접근하면 403 에러를 뱉는 nginx와는 달리
apache2는 해당 폴더를 탐색 모드로 보여주더라

이덕분에 발견할 수 있었지만 그건 그거

 

해서 apache2의 자동실행을 끄고

pi@raspberrypi:~ $ sudo systemctl disable apache2
Synchronizing state of apache2.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable apache2
Removed /etc/systemd/system/multi-user.target.wants/apache2.service.

 

재부팅해봤다

 

그랬더니 이제 nginx가 정상적으로 실행되고

더보기

pi@raspberrypi:~ $ systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2023-05-14 11:02:27 KST; 1min 18s ago
       Docs: man:nginx(8)
    Process: 555 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 600 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 601 (nginx)
      Tasks: 5 (limit: 3933)
        CPU: 194ms
     CGroup: /system.slice/nginx.service
             ├─601 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             ├─602 nginx: worker process
             ├─603 nginx: worker process
             ├─604 nginx: worker process
             └─605 nginx: worker process

May 14 11:02:26 raspberrypi systemd[1]: Starting A high performance web server and a reverse proxy server...
May 14 11:02:27 raspberrypi systemd[1]: Started A high performance web server and a reverse proxy server.

 

apache2는 조용히 찌그러져 있다

더보기

pi@raspberrypi:~ $ systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; disabled; vendor preset: enabled)
     Active: inactive (dead)
       Docs: https://httpd.apache.org/docs/2.4/

 

만족스러움

 

 

또 apache2의 행적을 조사하던 와중
이전 글 작성 시에는 모르던 파이홀의 서비스 이름도 알게 되었다

pi@raspberrypi:~ $ ps -aux | grep hole
pihole       554  0.1  0.2 620028  8024 ?        S<sl 11:02   0:01 /usr/bin/pihole-FTL -f
pi          1885  0.0  0.0   7352   632 pts/0    S+   11:20   0:00 grep --color=auto hole

 

apache 따위 없어도 해당 서비스는 정상 작동 중을 확인

더보기

pi@raspberrypi:~ $ systemctl status pihole-FTL
● pihole-FTL.service - Pi-hole FTL
     Loaded: loaded (/etc/systemd/system/pihole-FTL.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2023-05-14 11:02:26 KST; 18min ago
   Main PID: 554 (pihole-FTL)
      Tasks: 19 (limit: 3933)
        CPU: 1.525s
     CGroup: /system.slice/pihole-FTL.service
             └─554 /usr/bin/pihole-FTL -f

May 14 11:02:26 raspberrypi pihole-FTL[554]: [2023-05-14 11:02:26.845 554M]    ADDR2LINE: Enabled
May 14 11:02:26 raspberrypi pihole-FTL[554]: [2023-05-14 11:02:26.845 554M]    REPLY_WHEN_BUSY: Drop queries when the d>
May 14 11:02:26 raspberrypi pihole-FTL[554]: [2023-05-14 11:02:26.845 554M]    BLOCK_TTL: 2 seconds
May 14 11:02:26 raspberrypi pihole-FTL[554]: [2023-05-14 11:02:26.845 554M]    BLOCK_ICLOUD_PR: Enabled
May 14 11:02:26 raspberrypi pihole-FTL[554]: [2023-05-14 11:02:26.846 554M]    CHECK_LOAD: Enabled
May 14 11:02:26 raspberrypi pihole-FTL[554]: [2023-05-14 11:02:26.846 554M]    CHECK_SHMEM: Warning if shared-memory us>
May 14 11:02:26 raspberrypi pihole-FTL[554]: [2023-05-14 11:02:26.846 554M]    CHECK_DISK: Warning if certain disk usag>
May 14 11:02:26 raspberrypi pihole-FTL[554]: [2023-05-14 11:02:26.847 554M] Finished config file parsing
May 14 11:02:26 raspberrypi pihole-FTL[554]: [2023-05-14 11:02:26.847 554M] Creating mutex
May 14 11:02:27 raspberrypi pihole-FTL[554]: [2023-05-14 11:02:26.847

 

 

이렇게 변경하고 나서 아무리 여러모로 검토해 봐도
파이홀 구동에 아파치는 필요 없어 보인다
nginx가 대체하고 있기 때문이겠지만

 

더불어 php7.4마저 필요 없는 건 아닌지 하는 의심이 들었다
세트로 설치된 여러 잡것들도 마찬가지

 

 

좀 더 조사해 보니 파이홀 관리자 페이지 구동에는 php-fpm 이라는 녀석만 있으면 충분한 듯하다

해서 과감히 지워버리기로 했다
혹 문제가 생기면 다시 설치하면 그만이겠거니 하고

로그:

더보기

pi@raspberrypi:~ $ sudo apt purge php7.4 apache2
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  apache2-bin apache2-data apache2-utils libapache2-mod-php7.4 libapr1 libaprutil1 libaprutil1-dbd-sqlite3
  libaprutil1-ldap
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  apache2* php* php7.4*
0 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
After this operation, 740 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 54093 files and directories currently installed.)
Removing apache2 (2.4.56-1~deb11u2) ...
Removing php (2:7.4+76) ...
Removing php7.4 (7.4.33-1+deb11u3) ...
Processing triggers for man-db (2.9.4-2) ...
(Reading database ... 54033 files and directories currently installed.)
Purging configuration files for apache2 (2.4.56-1~deb11u2) ...

pi@raspberrypi:~ $ sudo apt autoremove
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  apache2-bin apache2-data apache2-utils libapache2-mod-php7.4 libapr1 libaprutil1 libaprutil1-dbd-sqlite3
  libaprutil1-ldap
0 upgraded, 0 newly installed, 8 to remove and 0 not upgraded.
After this operation, 11.4 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 53871 files and directories currently installed.)
Removing libapache2-mod-php7.4 (7.4.33-1+deb11u3) ...
Removing apache2-bin (2.4.56-1~deb11u2) ...
Removing apache2-data (2.4.56-1~deb11u2) ...
Removing apache2-utils (2.4.56-1~deb11u2) ...
Removing libaprutil1-ldap:arm64 (1.6.1-5+deb11u1) ...
Removing libaprutil1-dbd-sqlite3:arm64 (1.6.1-5+deb11u1) ...
Removing libaprutil1:arm64 (1.6.1-5+deb11u1) ...
Removing libapr1:arm64 (1.7.0-6+deb11u2) ...
Processing triggers for man-db (2.9.4-2) ...
Processing triggers for libc-bin (2.31-13+rpt2+rpi1+deb11u5) ...

 

이렇게 삭제한 후에
재부팅까지 했는데 아무런 문제가 없는 걸 확인했다

 

또 apache에 ntr당했던 홈페이지도 nginx로 돌아온걸 보니 너무 반갑다

 

애초에 php를 설치하려고 시도하지 말고 php-fpm만 설치했다면 이런 고생 안 하고 깔끔했겠지만 뭐
이미 늦었

 

 

+

추가로 크롤러가 Rate-limiting 에 막히는 문제도 해결됐다

 

어느 카페에서 로컬 DNS를 별도로 설정하는 파일의 정보를 얻어

$ sudo nano /etc/resolv.conf

공유기의 기본 dns였던 kt의 아이피를 추가하고 저장

 

해당 파일의 설정을 검색해서 찾은 내용들은
재부팅 후에 초기화된다는 둥 그걸 막는 추가 절차가 필요하다나 뭐라나
아마도 내 환경과는 많이 다른 듯해서 크게 참고가 되진 않았다


혹시 몰라 재부팅하고서 다시 테스트해 보니
더 이상 제한에 걸리지 않는다

 

또한 이제 필요 없어진 IGNORE_LOCALHOST 옵션을 지워버려도
여전히 크롤러는 Query Log에 잡히지 않아 깔끔한 통계가 유지된다

 

 

이로써 pihole 설치 후 불편 혹은 부족하게 느꼈던 부분들이 거의 해결되어 대만족

 

 

마지막 남은 의문은
pi.hole 이라는 로컬 도메인이 대체 어디서 적용되고 있는가
이걸 알아야 손을 대볼 궁리라도 하겠는데

 

주소창에 그냥 넣으면 검색 키워드로 인식하는 탓에
매번 http:// 까지 붙여줘야 해서 몹시도 귀찮거든

AND