커피닉스, 시스템 엔지니어의 쉼터
  apache설정에 따라 Content-Type은 어떻게 표시되나? 작성일 : 2009/04/17 13:24
 
  • 글쓴이 : 좋은진호 ( http://coffeenix.net/ )
  • 조회수 : 13828
     
    제  목 : apache설정에 따라 Content-Type은 어떻게 표시되나?
    작성자 : 좋은진호(truefeel)
    작성일 : 2009.4.9(목)
    정리일 : 2009.4.11(토)

    Apche 2.2.11버전과 php5 버전에서 문자셋 지정에 따라서 Request 헤더의 Content-Type (예. Content-Type: text/html )이 어떻게 되는지 살펴봤다.

    apache

    1. apache와 php에서 설정 방법

    다음은 apache와 php에서 각각 UTF-8 로 설정한 예이다.

    1) apache 2.2.x 의 httpd.conf
       AddDefaultCharset UTF-8

    2) php 5.2.x 의 php.ini
       default_charset = "UTF-8"

    apache에서는 .php와 .html 파일 모두 php로 처리하도록 설정되어 있다.

     AddType application/x-httpd-php .php .html 


    2. Content-Type: 헤더 결과

     
    ------------------------------------------------------------------------------------------
          apache설정     php설정      .html 결과                   .txt 결과
    ------------------------------------------------------------------------------------------
    1)    없음           없음         text/html                    text/plain
    2)    UTF-8          없음         text/html; charset=UTF-8     text/plain; charset=UTF-8
    3)    euc-kr         없음         text/html; charset=euc-kr    text/plain; charset=euc-kr
    4)    UTF-8          euc-kr       text/html; charset=euc-kr    text/plain; charset=UTF-8
    5)    없음           euc-kr       text/html; charset=euc-kr    text/plain
    6)    UTF-8          UTF-8        text/html; charset=UTF-8     text/plain; charset=UTF-8
    ------------------------------------------------------------------------------------------

    - .css 파일 : 어떤 설정에도 모두 text/css
    - .js  파일 : 어떤 설정에도 모두 application/javascript
     


    php로 인식하는 확장자(.php, .html)는 php에서 설정한 값을 우선으로 하였다. 즉, apache는 UTF-8로 설정하고, php는 euc-kr로 했다면 '4)'번 처럼 문자셋은 euc-kr로 표시된다. apache나 php 중 한 곳만 문자셋을 지정했다면(위에서 2, 3, 5번), 설정된 쪽의 문자셋을 따랐다.
    404 Not Found 요청일 경우 모두 'text/html; charset=iso-8859-1'으로 표시가 되었다. 그러나 apache에서 '404에러시 특정 html파일을 보여줘라'라고 'ErrorDocument 404' 설정을 했다면, 위의 .html 파일의 결과와 동일하게 표시되었다.



    커피닉스, 시스템 엔지니어의 쉼터 / URL : http://coffeenix.net/board_view.php?bd_code=1669