Notice
Recent Posts
Recent Comments
Link
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Tags
more
Archives
Today
Total
관리 메뉴

지석이의 일기

certbot renew 404 에러 본문

IT 에러경험

certbot renew 404 에러

91년도에 철산에서 태어난 최지석 2024. 6. 13. 08:55

cerbot renew 를 해놓은지 몇달이 지났는데, 잘되던 자동 업데이트가 고장이 났는지,,, 언제부터인지 작동이 되고 있지 않았다.

 

로그를 확인해보자.

IMPORTANT NOTES:
 - The following errors were reported by the server:

   Domain: {나의도메인}
   Type:   unauthorized
   Detail: {나의IP}.80: Invalid response from
   http://{나의도메인}/.well-known/acme-challenge/FI-192LHhyZ3ovzf6-wrqxfh-lN1dCGm1hTl8rFQaY0:
   404

   To fix these errors, please make sure that your domain name was
   entered correctly and the DNS A/AAAA record(s) for that domain
   contain(s) the right IP address.

 

.well-known/acme-challenge/ 가 404에러가 반환되고 있었던 것.

 

?뭐지 하고 nginx 설정 확인.

server {
    listen 80;
    listen [::]:80;
    server_name {나의 도메인};
  
    # 나머지 HTTP 요청을 HTTPS로 리디렉션
    location / {
        return 301 https://$host$request_uri;
    }
}

server {
    listen 443 ssl; # managed by Certbot
    server_name {나의 도메인};
    
    location / {
        proxy_pass         http://localhost:8080;
        proxy_http_version 1.1;
        proxy_set_header   Host $host;
        proxy_set_header   X-Forwarded-Host $host;      
        proxy_set_header   X-Forwarded-Server $host;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
    }

    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    ssl_certificate /etc/letsencrypt/live/{나의 도메인}/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/{나의 도메인}/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

 

보면 /.well-known/acme-challenge/ 의 urlpath를 캐치하는 구문이 없다.

 

그래서 아래와 같이 수정을 해주자.

 

server {
    listen 80;
    listen [::]:80;
    server_name {나의 도메인};
  
   # Let's Encrypt 인증 경로 예외 처리
    location ^~ /.well-known/acme-challenge/ {
        allow all;
        root /var/www/letsencrypt;
        try_files $uri =404;
    }
  
    # 나머지 HTTP 요청을 HTTPS로 리디렉션
    location / {
        return 301 https://$host$request_uri;
    }
}

server {
    listen 443 ssl; # managed by Certbot
    server_name {나의 도메인};

   

    location / {
        proxy_pass         http://localhost:8080;
        proxy_http_version 1.1;
        proxy_set_header   Host $host;
        proxy_set_header   X-Forwarded-Host $host;      
        proxy_set_header   X-Forwarded-Server $host;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
    }

    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    ssl_certificate /etc/letsencrypt/live/{나의 도메인}/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/{나의 도메인}/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

 

왜 80 포트쪽에만 적용을 시켰냐면, cerbot renew는 http(80)으로 확인을 하기 때문이다.

 

그리고 /var/www/letsencrypt/.well-known/acme-challenge 디렉토리가 있는지 확인!

mkdir -p /var/www/letsencrypt/.well-known/acme-challenge 으로 디렉토리가 없다면 생성해주고

sudo chmod -R 755 /var/www/letsencrypt/ 을 해서 누구나 읽고 쓰게 해준다.

간단하게 해당 디렉토리에 index.html 를 만들고

http://{나의도메인}/.well-known/acme-challenge/index.html 를 접속해서 정상적으로 200 반환 코드가 뜨면 성공!

이제 다시 cerbot renew를 실행 하면 100에 99는 여기서 해결 된다.

그외 안된다면

1. 도메인 dns 문제

2. 호스팅 방화벽 문제

가 있을수도 있다만!...

그런데

나의 경우 계속 해서 404에러가 뜬다.

 

혹시 내가 classpath나 서버설정이 잘못된건가? 해서

https(443) 설정쪽에도 추가를 했더니....

정상적으로 /.well-known/acme-challenge 디렉토리 쪽에 접속이 된다??....

https 로 접속시 nginx 로그에는 뭔가 남는데, 

http의 경우 nginx엔 아무것도 안뜨고 404 에러가 뜬다....

 

난 분명 

    location ^~ /.well-known/acme-challenge/ {
        allow all;
        root /var/www/letsencrypt;
        try_files $uri =404;
    }

이 구문을 복붙해서 80 과 443에 넣었는데...

443만 /.well-known/acme-challenge 디렉토리에 접속 되고 80은 되지 않는다.

https 접속시 정상적으로 index.html이 호출되고, http접속시 404 에러가 뜨는 상황이다.

이걸로 수십시간을 날리고...

 

혹시나 해서 봤더니 tomcat에서 80을 캐치 중이였음(???)

404 에러가 반환 된것은 스프링 상의 Request mapping path가 없어서 반환된 에러....

 

 

소스 디렉토리 conf쪽 server.xml를 열어보자...

Host 태그 구문 안에 

          <Context docBase="/var/www/letsencrypt/.well-known/acme-challenge" path="/.well-known/acme-challenge/" reloadable="true">
              <Resources allowLinking="true" />
          </Context>

이걸 추가해주면된다....

 

아직도 왜 80으로 들어가면 tomcat이 먼저 캐치하는진 이유를 모르겠다...

해당 구문을 추가하고 톰캣일 재시작하고 

http://{나의도메인}/.well-known/acme-challenge/index.html 를 접속하면... 드디어 뭔가 뜬다 ㅠㅠ