codestates / codestates/GongJang

Server Error Handling : https 배포 과정에서 발생한 에러

Open
#198 0 comments 0 reactions 1 assignee Claimed by @Gwangandong View on GitHub
error
Dominant language
JavaScript
Stars
0
Forks
2
PR merge metrics
No merged PRs in 30d

Description

## 어떤 에러인가요?
- ec2 인증서 미적용으로 발생한 혼합 컨텐츠 오류
- 원본 주소와 호스트(api)주소가 달라 발생한 크로스도메인 오류

## 에러 메시지
`xhr.js:210 Mixed Content: The page at '원본 주소' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://ec2-13-209-99-41.ap-northeast-2.compute.amazonaws.com:4000/posts'. This request has been blocked; the content must be served over HTTPS.`

`Access to XMLHttpRequest at '호스트주소' path from origin '원본 주소' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.`

` The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin '원본 주소' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.`

## 에러 핸들링 방법
`혼합 컨텐츠 오류는 https 웹앱과 http 서버에서 발생한다. 서버를 https로 만들어준다면 오류가 해결될 것으로 판단하여 서버에 AWS인증서를
설치, 적용하여 route53 도메인에 등록한 https://server.gongjang.tk 호스트로 적용후 클라이언트 재배포를 해봤더니 mixed content오류는 해결되었다`

`처음에는 단순히 서버에서 사용하는 cors 미들웨어의 origin 값의 변경을 통해 해결할 수 있을 것이라 생각했는데 잘 되지 않았다. ec2의 로드밸런서 적용이 되지 않았으며, 서버다운 시 로드밸런서가 서비스를 중단하는 현상까지 겹쳤다. 해결하기 위해 방법을 찾던 중 클래식 로드밸런서를 사용하면 오류가 덜 하다는 블로그를 참고하여 클래식으로 재설치하고 서버가 다운되지 않게 부분 부분 코드를 수정했는데 클래식 로드밸런서가 계속 먹통이라 찾아봤더니 상태검사를 TCP로 해야한다는 글을 발견했다. 이후 상태검사를 tcp로 바꾸고 실행했더니 정상작동 되는 것을 확인했다.`

## 에러 핸들링을 위해 참고한 레퍼런스 링크
mixed contents
[링크](https://ivorycode.tistory.com/entry/HTTP%EC%99%80-HTTPS-%EA%B7%B8%EB%A6%AC%EA%B3%A0-Mixed-Content)

cors
[링크1](https://developer.mozilla.org/ko/docs/Web/HTTP/CORS#Preflighted_requests)
[링크2](https://evan-moon.github.io/2020/05/21/about-cors/)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.