Print
카테고리: [ Apache HTTP Server ]
조회수: 16166

1. 개요

  Apache HTTP Server에 CORS 설정하는 법을 가이드 할 것이다.

 본 설정은 아래의 URL에 들어가면 자세한 설명이 있다.

https://benjaminhorn.io/code/setting-cors-cross-origin-resource-sharing-on-apache-with-correct-response-headers-allowing-everything-through/


2. 설정

  httpd.conf 파일이나 CORS를 적용하고자 하는 도메인의 virtual host에 적용하면 된다.
 
  아래의 설정을 적용하면 된다.
 
 
Header always set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS"
Header always set Access-Control-Max-Age "1800"
Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"
 > Header는 *로하면 브라우저에 따라 달라지며, 서비스별 요구되는 Header를 입력해야됨.
 > accept, Context-Type 등의 헤더가 추가되어야 GET 정상 수행.
 > Method 중에서 PUT이나 DELETE도 추가해도 되지만, 보안 수준에 따라 넣거나 빼면 된다.
 
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L]