Just Do IT!

[Error] Mixed Content 에러 해결 본문

개발 공부/Error

[Error] Mixed Content 에러 해결

MOON달 2023. 1. 27. 21:51
728x90
반응형

TIL에도 언급했듯이 vercel로 프로젝트를 배포했더니, api가 받아와지 않고 아래와 같은 에러가 발생했다.

 

Mixed Content: The page at '<URL>' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint '<URL>'. This request has been blocked; the content must be served over HTTPS.

 

이 에러를 구글링해보니 원인과 해결 방법을 알 수 가 있었다.

 

 

 

 

원인
  • 암호화된 HTTPS 페이지에 암호화되지 않은 HTTP를 통해 요청할 때 발생하는 에러
  • https 사이트에서 ajax를 사용해서 비동기로 http 사이트에 request를 요청해서 문제가 발생

이러한 원인 때문에 Mixed Content 에러가 발생한 것이고 이걸 해결하는 방법은 매우 간단했다.

 

 

 

 

 

 

해결 방법

html 파일의 <head> 태그 안에 아래 코드를 추가하면 오류가 해결된다.

 

<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">

이걸 추가하고 다시 push 후 배포된 사이트에서 적용되기를 기다렸더니 제대로 작동 완료.

 

 

 

 


stackoverflow 에도 동일한 질문이 남겨져 있어서 함께 첨부한다.

https://stackoverflow.com/questions/35178135/how-to-fix-insecure-content-was-loaded-over-https-but-requested-an-insecure-re

 

How to fix "insecure content was loaded over HTTPS, but requested an insecure resource"

This URL: https://slowapi.com I can't find the insecure content and the Chrome keeps complaining, Any ideas?

stackoverflow.com

 

추후에 같은 에러가 발생하면 다시 이 글로 돌아와야지.

728x90