사용자 도구

사이트 도구


nginx:basic_config

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

다음 판
이전 판
nginx:basic_config [2012/11/09 15:10]
kwon37xi 새로 만듦
nginx:basic_config [2021/10/19 22:53] (현재)
kwon37xi [Keep Alive]
줄 1: 줄 1:
 ====== nginx 기본 설정 ====== ====== nginx 기본 설정 ======
 +  * [[http://wiki.nginx.org/Configuration|nginx Configuration]]
   * [[http://wiki.nginx.org/HttpCoreModule|nginx HttpCoreModule]]   * [[http://wiki.nginx.org/HttpCoreModule|nginx HttpCoreModule]]
   * [[nginx:location|nginx location 설정]]   * [[nginx:location|nginx location 설정]]
 +
 +====== 서버 정보 숨기기 ======
 + * 응답으로 오는 Server 헤더에 nginx 정보가 들어간다. 이를 숨기는 것이 좋다.
 +  * [[https://serverfault.com/questions/214242/can-i-hide-all-server-os-info|nginx - Can I hide all server / os info?]]
 +  * 버전 번호만 삭제 <code>
 +// http,server,location 컨텍스트안에서
 +server_tokens off;
 +</code>
 +  * ''Server'' 헤더 자체 삭제. 추가 패키지 설치 필요할 수 있음(''nginx-extras'') <code>
 + more_clear_headers Server;
 +
 +</code>
 +====== timeout ======
 +<code>
 +send_timeout 60s; # 요청을 보낸 후 응답을 받기까지 대기 시간. 이 설정상 최소 60초 이내에 응답이 와야한다.
 +</code>
 +
  
 ===== error_page ===== ===== error_page =====
줄 15: 줄 33:
 error_page 404 =403 /forbidden.gif; error_page 404 =403 /forbidden.gif;
 </code> </code>
 +
 +===== Error Json =====
 +  * [[https://gist.github.com/weapp/99049e69477f924dafa7|Return common errors as json in Nginx]]
 +    * ''html'' 보다는 ''json'' 확장자를 선택하면 자동으로 ''application/json'' 응답을 해줄 듯.
 +    * [[https://github.com/nginx/nginx/blob/master/conf/mime.types|nginx mime.types]] 에 이미 ''application/json json;'' 이 들어있음.
 +<code>
 +error_page 500 /500.json;
 +location /500.json {
 +    return 500 '{"error": {"status_code": 500,"status": "Internal Server Error"}}';
 +}
 +</code>
 +
 +
 +===== header/cache expires =====
 +  * [[http://wiki.nginx.org/HttpHeadersModule|nginx HttpHeadersModule]] 헤더 설정을 통한 제어(expire 캐시등)
 +  * ''expires epoch;'' : 캐시 끄기
 +  * ''expires max;'' 31 December 2037 23:59:59 GMT, Cache-Control max-age to 10 years. 
 +<code>
 +  expires       24h;
 +  expires       modified +24h;
 +  expires       @15h30m;
 +  expires       0;
 +  expires       -1;
 +  expires       epoch;
 +  add_header    Cache-Control  private;
 +</code>
 +
 +
 +===== real ip =====
 +  * 로드 밸런서 등을 사용할 때 실제 요청 IP가 변형되는 현상 방지
 +  * [[http://nginx.org/en/docs/http/ngx_http_realip_module.html|Module ngx_http_realip_module]]
 +
 +===== Keep Alive =====
 +  * ''keepalive_timeout'' 을 통해서 값을 조정한다. 이를 ''0''으로 하면 keepalive가 꺼진다.<code>
 +keepalive_timeout 0;
 +</code>
 +  * ''keepalive''는 성능에 중요한 영향을 끼친다. [[nginx:performance|nginx Performance]] 참조.
 +  * [[web:performance|Web 성능 향상]] 에서 ''Keep Alive'' 참조
 +
 +===== default charset =====
 +  * 서빙하는 파일들에 기본 charset 헤더(''Content-Type'')을 지정하고자 할 때.
 +<code>
 +# charset_types 에 charset을 자동으로 붙여줄 mime type들 추가. text/html은 지정하지 말 것.
 +charset_types text/xml text/plain text/css application/javascript application/x-javascript application/rss+xml;
 +charset UTF-8;
 +</code>
 +
 +===== 참조문서 =====
 +
 +  * [[http://nginx.org/en/docs/control.html|Controlling nginx]]
 +  * [[https://juneyr.dev/nginx-basics|나는 nginx 설정이 정말 싫다구요 | juneyr.dev]]
nginx/basic_config.1352441407.txt.gz · 마지막으로 수정됨: 2012/11/09 15:10 저자 kwon37xi