nginx (engine-x)

lightweight, high-performance ● Apache(v.2.2.8) ○ used four worker processes(threaded mode) ○ 30% CPU ○ 17 MB of memory ○ to serve 6,500 requests per second.

● NGINX(v0.5.22) ○ used one worker, ○ 15% CPU ○ 1MB of memory ○ to serve 11,500 requests per second.

Why? ● Architecture ○ a master process, which delegates work to one or more worker processes. ○ each worker handles multiple requests in an eventdriven or asynchronous manner using special functionality from the Linux kernel(epoll/select/poll)

all the features for Web Sever ● static file serving. ● SSL/TLS support. ● Virtual Hosts. ● Reverse Proxying. ● Load Balancing. ● Compression. ● Access Controls. ● URL Rewriting. ● Custom logging. ● Server-side includes. ● WebDAV. ● FLV Streaming. ● FastCGI.

/etc/nginx/nginx.conf user www-data; worker_processes 1; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; events{ worker_connections 1024; } http{ include /etc/nginx/mime.types; default_type application/octet-stream; access_log /var/log/nginx/access.log; sendfile on; keepalive_timeout 65; tcp_nodelay on; gzip on; include /etc/nginx/sites-enabled/*; }

/etc/nginx/sites-enabled/default server{ listen 127.0.0.1:80; server_name basic; access_log /var/log/nginx/basic.access.log; error_log /var/log/nginx/basic.error.log; location / { root /var/www/basic; index index.html index.htm; } }

흐름 1. epoll_wait 2. 신규접속 여부에 따른 분기 3. HTTP의 Request line 처리 4. HTTP Header 수신해서 처리 ● NGX_HTTP_POST_READ_PHASE ● NGX_HTTP_SERVER_REWRITE_PHASE ● NGX_HTTP_FIND_CONFIG_PHASE ● NGX_HTTP_REWRITE_PHASE ● NGX_HTTP_POST_REWRITE_PHASE ● NGX_HTTP_PREACCESS_PHASE ● NGX_HTTP_ACCESS_PHASE ● NGX_HTTP_TRY_FILES_PHASE ● NGX_HTTP_CONTENT_PHASE ● ...

Rails on NGINX ● Rails의 한계를 NGINX에 확장 모듈로 도입하여 극복해보자! 1. 확장 모듈의 정의 작성(이름, 설정문자열 등) 2. 설정값 보유를 위한 구조체 및 설정값 반영 함수 구현 3. 확장할 Rails의 기능을 구현한 Handler를 적당한 PHASE에 추가(해당 PHASE 처리시 추가한 Handler가 실행 될 것) 4. Handler의 return값은 NGX_DECLINED or NGX_DONE 5. 필요한 확장 기능 동작 후, 결과값은 NGINX 기존 core 부분 이 알아서 client에게 전해줄 것이다. 6. 이제 필요한건 Compile 및 nginx.conf 설정.

결론 ● C Binary에 link 가능한 library가 사용가능할 것이다. ● C/C++로 Programming 가능한 기능이라면 다소 복잡하더 라도 확장하는 것이 가능할 것이다. ● Emiller's Guide To Nginx Module Development ● http://www.evanmiller.org/nginx-modules-guide.html ●

engine-x

/etc/nginx/sites-enabled/default server{ listen 127.0.0.1:80; server_name basic; access_log /var/log/nginx/basic.access.log; error_log /var/log/nginx/basic.error.log; location / { root /var/www/basic; index index.html index.htm;. }.

432KB Sizes 0 Downloads 314 Views

Recommend Documents

No documents