Using Nginx as a Load Balancer

Nginx is a relatively new web server that has a light footprint and relatively easy configuration. The following configuration demonstrates how to properly use nginx as a load balancer in front of two web servers.

pid /var/run/;

events {
    worker_connections 1024;

http {
    include mime.types;

    default_type application/octet-stream;
    sendfile on;
    keepalive_timeout 75;
    proxy_buffering off;
    log_not_found off;
    error_log /dev/null;
    access_log off;
    proxy_connect_timeout 20;
    client_header_timeout 60;
    client_body_timeout 60;
    send_timeout 60;

    server {
        location /nginx_status {
            stub_status on;
            access_log off;
            deny all;

    server {
        listen in:80;

        location ~ ^/(skin|media)/ {
        root /mnt/fs/vhosts/;
        expires 30d;

        location / {
        proxy_pass http://portero;

    upstream portero {
        server out1;
        server out2;

Related articles