Published on

Published in: Technology
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  1. 1. Whats NGINX?● Nginx (pronounced “Engine-X”) is an open source,high-performance:● HTTP server● Reverse proxy server for HTTP, SMTP, POP3 and IMAP protocols.
  2. 2. Nginx - History● Author Igor Sysoev● started development of Nginx in 2002.● first public release in 2004, -● Built to address the C10K problem.● Website
  3. 3. Why Nginx?● Stability● Performance● Security● Third party modules● Easy to configure
  4. 4. Features● Static file serving.● SSL/TLS support.● Virtual hosts.● Reverse proxying.● Load balancing.● Compression.● Access controls.● URL rewriting.● Custom logging.● Server-side includes.● FLV streaming.● FastCGI.
  5. 5. Why nginx is faster than apache?● Apache is a process-based server, while nginx is an event-based (asynchronous) web server.● Nginx is lighter then Apache.● Buffering.
  6. 6. Architecture● Master+workers● Event driven● Non-blocking● Single-threaded● Highlymodular
  7. 7. Master - Workers● Master -Monitor workers -Handle signals,notify workers (exit ,reconfiguration,update...)● Worker -Process client requests -Get cmd from master
  8. 8. Master process
  9. 9. Worker process
  10. 10. Modular
  11. 11. Event-driven Architecture (EDA)● EDA method is capable of handling more number of clients with less threads compared to conventional way (one thread for one client). Client 1 Client 2 worker Client N Client 1 Apache P.1 Apache P.2 Client 2 Apache P.N Client N
  12. 12. Event● ngx_event_t -Read -Write -Timeout● Callbacks● Handlers -ngx_event_accept -ngx_process_events_and_timers -ngx_handle_read_event -ngx_handle_write_event● Posted events -Posted accept event queue -Posted event queue
  13. 13. Non-blockingAsynchronous I/O allows a process to submit an I/O request without waiting for it to complete
  14. 14. Virtual Server● Port● Address● Server name● Core server conf.
  15. 15. Reconfig
  16. 16. Upgrading
  17. 17. Directives:● fair – send the request to the least busy backend server.● add_header – add custom headers to the response● limit_req_zone – limit requests for a client,prevent DOS attacks.● limit_conn_zone – limit concurent conections for a client.● stub_status – get current status of nginx.● error_pages – custom error page.● ip_hash;● backup;● If/set/rewrite.
  18. 18. Configserver { user www www;listen 80; worker_processes 2; server {server_name; listen 80;root /usr/local/www/; server_name;access_log /var/log/nginx/example.access.log; root /usr/local/www/;error_log /var/log/nginx/example.error.log; access_log /var/log/nginx/example.access.log;location / { error_log /var/log/nginx/example.error.log;# Rewrite rules can go here} location / { # Rewrite rules can go herelocation ~* .(?:ico|css|js|gif|jpe?g|png)$ { }expires max;add_header Pragma public; location ~* .(?:ico|css|js|gif|jpe?g|png)$ {add_header Cache-Control "public, must-revalidate, proxy-revalidate"; expires max;} add_header Pragma public; add_header Cache-Control "public, must-revalidate, proxy-revalidate";location ~ .php { }proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $remote_addr; location ~ .php$ { fastcgi_pass;proxy_set_header Host $host; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;proxy_pass; include fastcgi_params;} }include drop.conf; include drop.conf;} }
  19. 19. Front-End-(Nginx) and Back-End- (Apache) Advantages Client Frontend (NGINX) YES NO Static content HDD Backend (files) (Apache)
  20. 20. Proxy balancingupstream backend {server;server weight=3; server max_fails=3fail_timeout=10s; }
  21. 21. Nginx – Memcached - Apacheserver { location / { set $memcached_key $uri; memcached_pass; default_type text/html; error_page 404 = @fallback; } location @fallback { proxy_pass backend; }}
  22. 22. RewriteApache:RewriteCond %{HTTP_HOST} ^$ [NC]RewriteRule ^(.*)$$1 [L,R=301]Nginx:server { server_name; return 301 $scheme://$request_uri;}server { server_name; [...]}
  23. 23. Nginx vs Apache
  24. 24.
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.