SlideShare a Scribd company logo
Front end servers and
nginx
 What, when and how?
Simple web application

Basic configuration:

•Tomcat, Resin, JBoss, Apache Http + php, ...
•MySQL, PostgreSQL, Oracle, ...


Enough?
What does your server?

General list:

•Process requests to static resource (css, images, etc)
•Process request to dynamic part (servlet).
•Exchange with database.
•Process schedulers, quartz, etc
•Generate reports, calculate statistic...


One day he may say: "enough!". Be ready!
Why sites are dying?

Few problems:

•Weak hardware
•Weak client connection channel
•Lots of requests to static resource (especially images
and video)
•High loads
Front end

Front end is an interface between the user and back
end.

Most popular servers to front end role:
•nginx
•lighthttpd
•apache httpd
•...
Nginx

Popular and productive

Nginx - is a HTTP and reverse proxy server, as well as
mail proxy server, written by Igor Sysoev.
According to Netcraft nginx served or proxied 12.49%
busiest sites in July 2012.
Who are using nginx?

They are:

•Rambler
•Yandex
•Mail.ru
•vk
Features and figures
             •   100 000 connection per server
             •   60 000 requests per second
             •   2.5 Mb per 10 000 keep-alive
                 connections
             •   No threads
Features and figures
What will nginx do?

General function of nginx or
another front end server:

•Static content
•Reserve proxying with caching
•Compression response
•Prepared thumbnails for images
•Uploading, downloading, streaming, ...
Let's start with nginx

Simple configuration

worker_processes 4;

events {
  worker_connections 4096;
}
Virtual hosts
server {
    listen         80 default;
    server_name        www.domain.com;
    root           /home/domain.com


    location / {
        proxy_pass http://localhost:8080;
        proxy_redirect off;
                 proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
Other virtual hosts

As much as you need:
server {
 listen    80;
 server_name img.domain.com;

    index    index.php;
    root    /home/domain.com/img;
}
Compressing
gzip on;
gzip_min_length 1000;
gzip_proxied   any;
gzip_types     text/plain application/xml text/javascript text/css text/json;
gzip_disable   "msie6";
gzip_comp_level 4;
Thumbnails, proxy to resize
#Image resize location
location ~ ^/preview/(?P<oper>[abc])/(?P<remn>.+) {
           root $path/cache;
           error_page 404 = @fetch;
}

location @fetch {
           root $path/cache;
           proxy_pass http://127.0.0.1:81/$oper/$remn;
           proxy_store on;
}
Thumbnails, resize
location ~ ^/s/(.+) {
     image_filter_buffer 6M;
     alias $path/static/$1;
     try_files "" @404;

     image_filter crop 80 80;
}
location ~ ^/c/[^/]+/(d+|-)x(d+|-)/(.+) {
     set $width $1;
     set $height $2;
     alias $path/static/$3;
     try_files "" @404;
     if ($secure_link = "") { return 404; }
     image_filter crop $width $height;
}
Secured link
location ~ ^/int/(.*)$ {
             alias $path/$1;
             internal;
}

@RequestMapping("/secret/**")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public void checkAccess(HttpServletRequest request,
                                               HttpServletResponse response) {
             String img = request.getServletPath();
             String path = "/int/" + img;
             response.setHeader("X-Accel-Redirect", path);
}
Secured link
location ~ ^/int/(.*)$ {
             alias $path/$1;
             internal;
}

@RequestMapping("/secret/**")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public void checkAccess(HttpServletRequest request,
                                               HttpServletResponse response) {
             String img = request.getServletPath();
             String path = "/int/" + img;
             response.setHeader("X-Accel-Redirect", path);
}
Uploading
location /upload {
            upload_pass @backend;
            upload_store /location;
            client_max_body_size 15m;
            upload_max_file_size 4m;


            # Set specified fields in request body
            upload_set_form_field $upload_field_name.content_type "$upload_content_type";
            upload_set_form_field $upload_field_name.path "$upload_tmp_path";
            upload_cleanup 400 403 404 405 499 500-505;
}


location @backend {
            proxy_pass http://127.0.0.1:8080;
}
Frontend Servers and NGINX: What, Where and How

More Related Content

PPT
eZ Publish Cluster Unleashed
PDF
Ground Control to Nomad Job Dispatch
PPTX
Distributed in memory data grid
PPT
Lightweight DAS components in Perl
PPT
Oracle database - Get external data via HTTP, FTP and Web Services
PDF
Terraforming the Kubernetes Land
PPT
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
PDF
How to connect AngularJS to servers
eZ Publish Cluster Unleashed
Ground Control to Nomad Job Dispatch
Distributed in memory data grid
Lightweight DAS components in Perl
Oracle database - Get external data via HTTP, FTP and Web Services
Terraforming the Kubernetes Land
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
How to connect AngularJS to servers

What's hot (19)

PDF
Infrastructure as code terraformujeme cloud
PPTX
MySQL Slow Query log Monitoring using Beats & ELK
PDF
Presto in Treasure Data (presented at db tech showcase Sapporo 2015)
PDF
Getting Started with Couchbase Ruby
PDF
Facebook的缓存系统
PDF
Data models in Angular 1 & 2
PDF
GraphQL Los Angeles Meetup Slides
PDF
How to replace rails asset pipeline with webpack?
PPTX
DevOps Fest 2019. Сергей Марченко. Terraform: a novel about modules, provider...
PPT
Spring data iii
PPTX
Drupal 8 Deep Dive: What It Means for Developers Now that REST Is in Core
PDF
Vancouver presentation
PPT
Html5 drupal7 with mandakini kumari(1)
PPTX
Elk with Openstack
PDF
CouchDB Mobile - From Couch to 5K in 1 Hour
PDF
Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Berlin...
DOC
PPTX
Big data - Solr Integration
ODP
Introducing CouchDB
Infrastructure as code terraformujeme cloud
MySQL Slow Query log Monitoring using Beats & ELK
Presto in Treasure Data (presented at db tech showcase Sapporo 2015)
Getting Started with Couchbase Ruby
Facebook的缓存系统
Data models in Angular 1 & 2
GraphQL Los Angeles Meetup Slides
How to replace rails asset pipeline with webpack?
DevOps Fest 2019. Сергей Марченко. Terraform: a novel about modules, provider...
Spring data iii
Drupal 8 Deep Dive: What It Means for Developers Now that REST Is in Core
Vancouver presentation
Html5 drupal7 with mandakini kumari(1)
Elk with Openstack
CouchDB Mobile - From Couch to 5K in 1 Hour
Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Berlin...
Big data - Solr Integration
Introducing CouchDB
Ad

Viewers also liked (20)

PDF
User Behavior: Interacting With Important Website Elements
PPT
Эффективный JavaScript - IQLab Frontend Fusion 2012
PDF
Databases on Client Side
PDF
Unexpected achievements 2013
PDF
QA evolution, in pictures
PDF
Testing schools overview
PPT
Mastering Java ByteCode
PPT
Правила хорошего SEO тона в Frontend разработке
PDF
non-blocking java script
PPT
External Widgets Performance
PPT
Психология восприятия и UX дизайн
PDF
Seo and Marketing Requirements in Web Architecture
PDF
Getting to know magento
PDF
Management and Communications (IPAA)
PDF
Lupan big enterprise ecommerce fusion 2013
PDF
Quick Intro to Clean Coding
PPT
Доступность веб-сайтов: WWW для всех?
PDF
Developing for e commerce is important
User Behavior: Interacting With Important Website Elements
Эффективный JavaScript - IQLab Frontend Fusion 2012
Databases on Client Side
Unexpected achievements 2013
QA evolution, in pictures
Testing schools overview
Mastering Java ByteCode
Правила хорошего SEO тона в Frontend разработке
non-blocking java script
External Widgets Performance
Психология восприятия и UX дизайн
Seo and Marketing Requirements in Web Architecture
Getting to know magento
Management and Communications (IPAA)
Lupan big enterprise ecommerce fusion 2013
Quick Intro to Clean Coding
Доступность веб-сайтов: WWW для всех?
Developing for e commerce is important
Ad

Similar to Frontend Servers and NGINX: What, Where and How (20)

PDF
Nginx pres
PDF
ITB2017 - Nginx Effective High Availability Content Caching
PDF
Using NGINX as an Effective and Highly Available Content Cache
PDF
Caché acelerador de contenido
KEY
Nginx - Tips and Tricks.
PPTX
Reverse proxies & Inconsistency
PDF
Nginx + PHP
PDF
Nginx Workshop Aftermath
PPTX
High Availability Content Caching with NGINX
PDF
High Availability Content Caching with NGINX
PPTX
Nginx A High Performance Load Balancer, Web Server & Reverse Proxy
PPTX
WordPress + NGINX Best Practices with EasyEngine
PDF
How to secure your web applications with NGINX
PPTX
NGINX High-performance Caching
PDF
What is Nginx and Why You Should to Use it with Wordpress Hosting
PDF
Deploying nginx with minimal system resources
PDF
Apache httpd 2.4 Reverse Proxy: The Hidden Gem
KEY
Scaling application servers for efficiency
PDF
Django and Nginx reverse proxy cache
PDF
Scale Apache with Nginx
Nginx pres
ITB2017 - Nginx Effective High Availability Content Caching
Using NGINX as an Effective and Highly Available Content Cache
Caché acelerador de contenido
Nginx - Tips and Tricks.
Reverse proxies & Inconsistency
Nginx + PHP
Nginx Workshop Aftermath
High Availability Content Caching with NGINX
High Availability Content Caching with NGINX
Nginx A High Performance Load Balancer, Web Server & Reverse Proxy
WordPress + NGINX Best Practices with EasyEngine
How to secure your web applications with NGINX
NGINX High-performance Caching
What is Nginx and Why You Should to Use it with Wordpress Hosting
Deploying nginx with minimal system resources
Apache httpd 2.4 Reverse Proxy: The Hidden Gem
Scaling application servers for efficiency
Django and Nginx reverse proxy cache
Scale Apache with Nginx

More from Ecommerce Solution Provider SysIQ (13)

PDF
PDF
Developing for e commerce is important
PDF
PDF
PDF
Scalability and performance for e commerce
PDF
QA evolution to the present day
PDF
Manifest of modern engineers
PDF
Speed Up Your Website
PPTX
IGears: Template Architecture and Principles
PPT
Interactive web prototyping
PPT
Модульные сетки в реальном мире
PPT
Understanding Annotations in Java
Developing for e commerce is important
Scalability and performance for e commerce
QA evolution to the present day
Manifest of modern engineers
Speed Up Your Website
IGears: Template Architecture and Principles
Interactive web prototyping
Модульные сетки в реальном мире
Understanding Annotations in Java

Recently uploaded (20)

PPTX
MYSQL Presentation for SQL database connectivity
PDF
Empathic Computing: Creating Shared Understanding
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Modernizing your data center with Dell and AMD
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Cloud computing and distributed systems.
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
A Presentation on Artificial Intelligence
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
cuic standard and advanced reporting.pdf
PDF
Machine learning based COVID-19 study performance prediction
MYSQL Presentation for SQL database connectivity
Empathic Computing: Creating Shared Understanding
Review of recent advances in non-invasive hemoglobin estimation
NewMind AI Monthly Chronicles - July 2025
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Encapsulation_ Review paper, used for researhc scholars
The Rise and Fall of 3GPP – Time for a Sabbatical?
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Modernizing your data center with Dell and AMD
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
The AUB Centre for AI in Media Proposal.docx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Cloud computing and distributed systems.
Diabetes mellitus diagnosis method based random forest with bat algorithm
A Presentation on Artificial Intelligence
Network Security Unit 5.pdf for BCA BBA.
cuic standard and advanced reporting.pdf
Machine learning based COVID-19 study performance prediction

Frontend Servers and NGINX: What, Where and How

  • 1. Front end servers and nginx What, when and how?
  • 2. Simple web application Basic configuration: •Tomcat, Resin, JBoss, Apache Http + php, ... •MySQL, PostgreSQL, Oracle, ... Enough?
  • 3. What does your server? General list: •Process requests to static resource (css, images, etc) •Process request to dynamic part (servlet). •Exchange with database. •Process schedulers, quartz, etc •Generate reports, calculate statistic... One day he may say: "enough!". Be ready!
  • 4. Why sites are dying? Few problems: •Weak hardware •Weak client connection channel •Lots of requests to static resource (especially images and video) •High loads
  • 5. Front end Front end is an interface between the user and back end. Most popular servers to front end role: •nginx •lighthttpd •apache httpd •...
  • 6. Nginx Popular and productive Nginx - is a HTTP and reverse proxy server, as well as mail proxy server, written by Igor Sysoev. According to Netcraft nginx served or proxied 12.49% busiest sites in July 2012.
  • 7. Who are using nginx? They are: •Rambler •Yandex •Mail.ru •vk
  • 8. Features and figures • 100 000 connection per server • 60 000 requests per second • 2.5 Mb per 10 000 keep-alive connections • No threads
  • 10. What will nginx do? General function of nginx or another front end server: •Static content •Reserve proxying with caching •Compression response •Prepared thumbnails for images •Uploading, downloading, streaming, ...
  • 11. Let's start with nginx Simple configuration worker_processes 4; events { worker_connections 4096; }
  • 12. Virtual hosts server { listen 80 default; server_name www.domain.com; root /home/domain.com location / { proxy_pass http://localhost:8080; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
  • 13. Other virtual hosts As much as you need: server { listen 80; server_name img.domain.com; index index.php; root /home/domain.com/img; }
  • 14. Compressing gzip on; gzip_min_length 1000; gzip_proxied any; gzip_types text/plain application/xml text/javascript text/css text/json; gzip_disable "msie6"; gzip_comp_level 4;
  • 15. Thumbnails, proxy to resize #Image resize location location ~ ^/preview/(?P<oper>[abc])/(?P<remn>.+) { root $path/cache; error_page 404 = @fetch; } location @fetch { root $path/cache; proxy_pass http://127.0.0.1:81/$oper/$remn; proxy_store on; }
  • 16. Thumbnails, resize location ~ ^/s/(.+) { image_filter_buffer 6M; alias $path/static/$1; try_files "" @404; image_filter crop 80 80; } location ~ ^/c/[^/]+/(d+|-)x(d+|-)/(.+) { set $width $1; set $height $2; alias $path/static/$3; try_files "" @404; if ($secure_link = "") { return 404; } image_filter crop $width $height; }
  • 17. Secured link location ~ ^/int/(.*)$ { alias $path/$1; internal; } @RequestMapping("/secret/**") @PreAuthorize("hasRole('ROLE_ADMIN')") public void checkAccess(HttpServletRequest request, HttpServletResponse response) { String img = request.getServletPath(); String path = "/int/" + img; response.setHeader("X-Accel-Redirect", path); }
  • 18. Secured link location ~ ^/int/(.*)$ { alias $path/$1; internal; } @RequestMapping("/secret/**") @PreAuthorize("hasRole('ROLE_ADMIN')") public void checkAccess(HttpServletRequest request, HttpServletResponse response) { String img = request.getServletPath(); String path = "/int/" + img; response.setHeader("X-Accel-Redirect", path); }
  • 19. Uploading location /upload { upload_pass @backend; upload_store /location; client_max_body_size 15m; upload_max_file_size 4m; # Set specified fields in request body upload_set_form_field $upload_field_name.content_type "$upload_content_type"; upload_set_form_field $upload_field_name.path "$upload_tmp_path"; upload_cleanup 400 403 404 405 499 500-505; } location @backend { proxy_pass http://127.0.0.1:8080; }