-
[Nginx] CORS 설정 및 테스트Web/Nginx 2022. 11. 7. 20:00
cors설정 후 제대로 되었는지 테스트 하는 방법.
1. nginx default.conf 아래 내용 추가
location / { ... add_header 'Access-Control-Allow-Origin' '*'; proxy_pass "example.com" ... }
2.아래 zip파일이나 깃허브 링크로 프로젝트를 받아 main.js의 url을 수정후 실행
nicks-cors-test-main.zip0.00MBhttps://github.com/njgibbon/nicks-cors-test
GitHub - njgibbon/nicks-cors-test: Simple HTML & JS Tool to quickly test CORS locally.
Simple HTML & JS Tool to quickly test CORS locally. - GitHub - njgibbon/nicks-cors-test: Simple HTML & JS Tool to quickly test CORS locally.
github.com
3. url을 google로 실행시 cors에러가 나고 github로 실행시 cors에러가 나지 않는다.
내가 cors를 해지한 도메인을 넣어 테스트 해본다.
F12의 console에 에러가 나지 않으면 성공.
function main() { console.log("nicks-cors-test"); $.ajax ({ url: "https://google.com", //url: "https://api.github.com", success: function(data) { console.log(data); } }); }
반응형'Web > Nginx' 카테고리의 다른 글
[Nginx] 401 cors에러 해결법 (0) 2022.12.01 [Nginx] 이미지 경로 설정 (0) 2022.08.19 Nginx 실제 client ip 값 조회 (0) 2022.07.21