사이트가 유효한 캐싱 전략으로 정적 자산을 제공하지 않습니다. 퍼포먼스
WordPress 의 서버 건강상태 체크에서 계속 정적 캐시가 설정되지 않았다는 메시지가 나왔다. ChatGPT 는 이미 개인 서버로는 충분한 반응 속도가 나오니, 굳이 할 필요는 없다고 했지만…
헤헤..
ChatGPT 는 가장 먼저 WordPress 가 어떤 웹서버 기반에서 돌아가지는 지를 알아내려고 했다.
sudo ss -tlnp | grep -E ‘:80|:443’
sudo systemctl status apache2
sudo systemctl status nginx
구동 환경은 Apache2 고, ChatGPT 가 짠 스크립트는 다음과 같다.
<IfModule mod_expires.c> ExpiresActive On
ExpiresByType text/css "access plus 1 year" ExpiresByType application/javascript "access plus 1 year"
ExpiresByType image/png "access plus 1 year" ExpiresByType image/jpeg "access plus 1 year" ExpiresByType image/gif "access plus 1 year" ExpiresByType image/webp "access plus 1 year"
ExpiresByType font/woff2 "access plus 1 year" ExpiresByType font/woff "access plus 1 year"</IfModule>
<IfModule mod_headers.c> <FilesMatch "\.(css|js|png|jpg|jpeg|gif|webp|woff|woff2)$"> Header set Cache-Control "public, max-age=31536000, immutable" </FilesMatch></IfModule>
스크립트의 모듈을 활성화 하기 위한 명령
sudo a2enmod expires
sudo a2enmod headers
위 스크립트를 /etc/apache2/conf-available/cache-control.conf 라는 파일을 생성하여 집어넣었다.
그리고 설정 파일을 활성화 하는 명령
Sudo a2enconf cache-control
새로운 설정 파일을 리로드
sudo systemctl reload apache2
여기까지 하고 되겠지 하고 다른 주제로 넘어갔었는데, 실제로 확인해보니 WordPress 에서 정적 Cache 가 설정되어 있지 않다는 메시지가 계속 나왔다.
그래서 검색하여 아까 만들었던 cache-control.conf 에 볼드로 강조한 부분을 추가로 삽입했다.
<IfModule mod_expires.c> ExpiresActive On
ExpiresDefault “access plus 1 month”
ExpiresByType text/css "access plus 1 year" ExpiresByType application/javascript "access plus 1 year" ExpiresByType image/png "access plus 1 year" ExpiresByType image/jpeg "access plus 1 year" ExpiresByType image/jpg "access plus 1 year"
...</IfModule>
여기까지 하니까 WordPress 에서 정적 Cache 에 대한 메시지가 사라졌다.
ChatGPT 는 서버 설정 하기 싫으면 플러그인을 사용해도 된다고 제시해줬다.
플러그인으로도 가능
서버 설정을 건드리기 싫다면:
- LiteSpeed Cache (LiteSpeed 사용 시)
- WP Fastest Cache
- W3 Total Cache
같은 캐시 플러그인이 자동으로 헤더를 추가해 주기도 해.
