Set Up Nginx For Hosting Rails Application

Nginx (pronounced “engine X”) is a free, open-source, lightweight, high-performance HTTP server and reverse proxy , as well as an IMAP/POP3 proxy server, licensed under a BSD-like license. Nginx is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption.

Nginx is one of a handful of servers written to address the C10K problem. Unlike traditional servers, Nginx doesn’t rely on threads to handle requests. Instead it uses a much more scalable event-driven (asynchronous) architecture. This architecture uses small, but more importantly, predictable amounts of memory under load.

Even if you don’t expect to handle thousands of simultaneous requests, you can still benefit from Nginx’s high-performance and small memory footprint. Nginx scales in all directions: from the smallest VPS all the way up to clusters of servers.

It runs on UNIX, GNU/Linux, BSD variants, Mac OS X, Solaris, and Microsoft Windows.

Installation

To install nginx you would require passenger first:

install passengar:

$ gem install passenger

$ passenger -v

In order to let Passenger install Nginx, you need to install a dependency first.

$ sudo apt-get install libcurl4-openssl-dev

use rvmsudo than regular sudo to install nginx

$rvmsudo passenger-install-nginx-module

start nginx

$ sudo /opt/nginx/sbin/nginx

Configuration

$ sudo nano /opt/nginx/conf/nginx.conf (VPS)

$ sudo /etc/init.d/nginx reload (VPS)

configuration file example

server {

listen 80;

server_name www.yourdomain.com;

root /home/Nagakiran/test_app/current/public;

passenger_enabled on;

#charset koi8-r;

#access_log logs/host.access.log main;

#location / {

# root html;

# index index.html index.htm;

#}

Features of Nginx

Overview

Nginx can deploy dynamic HTTP content on a network using FastCGI, SCGI handlers for scripts, uWSGI application servers or Phusion Passenger module, and can serve as a software load balancer.

Nginx uses an asynchronous event-driven approach to handling requests which can provide more predictable performance under high loads, in contrast to the Apache HTTP server model that defaults to a threaded or process-oriented approach to handling requests.

Usage

Originally, nginx was developed to fill the needs of various websites run by Rambler, for which it was serving 500 million requests per day as of September 2008

According to Netcraft’s March 2012 Web Server Survey, nginx was found to be the third most widely used web server across all domains (10.15% of surveyed sites) and the second most widely used web server for all “active” sites (12.77% of surveyed sites). According to W3Techs it is used by 10.6% of the top 1 million websites, and by 25.6% of the top 1,000 websites.According to BuiltWith, it is used on 13.76% of the top 10,000 websites, and its growth within the top 10k, 100k and 1 million segments is increasing.

Wikipedia uses nginx as its SSL termination proxy.

Basic HTTP features

* Ability to handle more than 10000 simultaneous connections with a low memory footprint (~2.5 MB per 10k inactive HTTP keep-alive connections) * Handling of static files, index files, and auto-indexing * Reverse proxy with caching * Load balancing * Fault tolerance * SSL with SNI support * FastCGI, SCGI, uwsgi support with caching * Name- and IP-based virtual servers * FLV streaming * MP4 streaming, using the contrib Streaming Lite module[12] (not updated since 2008) or since version 1.1.3 using the built-in MP4 Streaming Module[13] * Web page access authentication * gzip compression * URL rewriting * Custom logging * Response rate and concurrent requests limiting * Server Side Includes * IP-based geolocation * WebDAV

Mail proxy features

* SSL support * STARTTLS support * SMTP, POP3, and IMAP proxy

Other features

Upgrading executable and configuration on the fly (without client connections loss).

Get in touch with us.

Subscribe For Latest Updates

Related Posts

Leave a Comment

Your email address will not be published. Required fields are marked *

en_USEnglish