nginx 에 특정 도메인에 대해 CORS 를 오픈해줄때 (mydomain.com)
.
.
location ^~ /emoticons {
# CORS 헤더 추가
add_header 'Access-Control-Allow-Origin' 'https://mydomain.com' always;
add_header 'Access-Control-Allow-Methods' 'GET' always;
add_header 'Access-Control-Allow-Headers' 'Authorization,Content-Type' always;
# OPTIONS 요청에 대한 처리
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' 'https://mydomain.com';
add_header 'Access-Control-Allow-Methods' 'GET';
add_header 'Access-Control-Allow-Headers' 'Authorization,Content-Type';
add_header 'Content-Length' '0';
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Access-Control-Max-Age' 1728000;
return 204;
}
}
.
.
이후 nginx 설정 테스트 후 재시작
nginx -t
service nginx restart
끝.
'Server > Nginx' 카테고리의 다른 글
nginx cache 설정하기 (2) | 2024.11.13 |
---|---|
프록시 통해서 전달되는 svg 파일도 gzip 압축하여 전송 설정 (0) | 2024.06.06 |
nginx 파일 업로드 최대 용량 제한 (0) | 2024.06.06 |
nginx proxy 설정 (0) | 2024.06.06 |
nginx gzip 설정 (웹사이트 컨텐츠 압축하여 전송) (0) | 2024.06.06 |