Upgrade to Pro — share decks privately, control downloads, hide ads and more …

nginx

 nginx

Quick introduction of nginx and the configs that a developer can use on a day by day base

Bert Pattyn

April 12, 2012
Tweet

Other Decks in Technology

Transcript

  1. Why nginx? • event based -> more connections, less overhead

    • efficiency • smaller memory footprint • friendly configuration format
  2. Modules • core modules: core, events • standard http modules

    • optional http modules Overview: http://wiki.nginx.org/Modules
  3. server_name 1. full, static names www.example.be 2. names with a

    wildcard at the start *.example.be 3. names with a wildcard at the end www.example.* 4. names with regex ~^www\d+\.example\.be$ 5. wildcard _
  4. server { listen 80 default; server_name _ example.be; rewrite ^(.*)

    http://www.example.be$1 permanent; } server { server_name www.example.be }
  5. flags 1. last (stop processing, restart search for location blocks)

    2. break (stop rewrite processing, continue non-rewrite processing in current location block) 3. redirect (302) 4. permanent (301)
  6. server { gzip on; gzip_disable "MSIE [1-6]\.(?!.*SV1)"; gzip_comp_level 6; gzip_types

    text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js ; }
  7. server { location ~ \.(css|js)$ { expires 31d; add_header Pragma

    "public"; add_header Cache-Control "public, must-revalidate, proxy-revalidate"; } }
  8. Other modules • Auth Basic - Basic HTTP authentication •

    Browser - Interpret "User-Agent" string • SSL - HTTPS/SSL support • ...
  9. server { valid_referers none blocked www.example.be example.be; if($invalid_referer) { return

    403; } if($http_cookie ~* "id=([^;] +)(?;;|$)") { set $id $1; } if ($http_user_agent ~ MSIE) { rewrite ^(.*)$ /msie/$1 break; }