Jump to: navigation, search


NGINX is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. 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 large clusters of servers.

  • Realized on :
    • Debian 8
    • Ubuntu 14.04
  • nginx versions :
    • 1.6.2
    • 1.4.6

Simple configuration

Install packages

aptitude install nginx -y

Files location

  • Configuration : /etc/nginx/*


Creating virtual host configurations on your Apache server does not magically cause DNS entries to be created for those host names. You must have the names in DNS, resolving to your IP address, or nobody else will be able to see your web site. You can put entries in your hosts file for local testing, but that will work only from the machine with those hosts entries.


  • Create your site directory and index
mkdir -p /var/www/
echo "Hello b*tches!" > /var/www/
chown www-data: /var/www/
  • Create the Vhost config file : /etc/nginx/sites-available/
tee /etc/nginx/sites-available/ << EOF &> /dev/null
server {
    listen 80;
    charset utf-8;
    root /var/www/html;
    index index.html;
  • Enable
ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/
service nginx reload

Configure php-fpm with Nginx

Configure PHP-FPM

Use PHP-FPM in virtualhost

  • Edit /etc/nginx/sites-available/
server {
    listen 80;
    charset utf-8;
    root /var/www/html;
    index index.html;

    # Add following block
    location ~ \.php(?:$|/) {
        fastcgi_pass unix:/var/run/php5-fpm-www.sock;                       # path to php-fpm unix socket
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
  • Enable virtualhost and restart nginx