# Load balancing random 503

**URL:** <https://www.ruby-forum.com/t/load-balancing-random-503/223019>\
**Category:** NGINX\
**Created:** [September 19, 2012, 8:16am UTC](https://www.ruby-forum.com/t/load-balancing-random-503/223019 "2012-09-19T08:16:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [September 19, 2012, 8:16am UTC](https://www.ruby-forum.com/t/load-balancing-random-503/223019/1 "2012-09-19T08:16:03Z")

</div>

Hi there  
I have an instance on ec2 acting as a load balancer for 4 apache2  
servers.  
The instance is ubuntu precise with nginx 1.2.3  
The instance has 4 computing units and 3.75 GB memory

Everything is working ok, except I get random 503 for some images.  
I have a page that loads about 20 images, they never load all, randomly  
some  
of them don’t load and not the same ones every time.

Any help is appreciated.

nginx.conf:

user www-data;  
worker\_processes 8;  
pid /var/run/nginx.pid;

events {  
worker\_connections 4096;

# multi\_accept on;

}

http {

## 

# Basic Settings

## 

sendfile on;  
tcp\_nopush on;  
tcp\_nodelay on;  
keepalive\_timeout 65;  
types\_hash\_max\_size 2048;

# server\_tokens off;

server\_names\_hash\_bucket\_size 64;  
map\_hash\_bucket\_size 128;

# server\_name\_in\_redirect off;

### override default ssl settings

ssl\_session\_timeout 10m;  
proxy\_ssl\_session\_reuse off;  
ssl\_session\_cache shared:SSL:16m;  
ssl\_protocols SSLv3 TLSv1;  
ssl\_ciphers  
ALL:!ADH:!kEDH:!aNULL:!MD5:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;  
#ssl\_ciphers HIGH:!aNULL:!MD5:!kEDH;  
#ssl\_ciphers ALL:!aNULL:!ADH:!eNULL:!MEDIUM:!LOW:!EXP:RC4 RSA:  
HIGH;  
ssl\_prefer\_server\_ciphers on;

include /etc/nginx/mime.types;  
default\_type application/octet-stream;

## 

# Logging Settings

## 

access\_log /var/log/nginx/access.log;  
error\_log /var/log/nginx/error.log;

## 

# Gzip Settings

## 

gzip on;  
gzip\_disable “msie6”;

# gzip\_vary on;

# gzip\_proxied any;

# gzip\_comp\_level 6;

# gzip\_buffers 16 8k;

# gzip\_http\_version 1.1;

# gzip\_types text/plain text/css application/json

application/x-javascript  
text/xml application/xml application/xml+rss text/javascript;

## 

# nginx-naxsi config

## 

# Uncomment it if you installed nginx-naxsi

## 

#include /etc/nginx/naxsi\_core.rules;

## 

# nginx-passenger config

## 

# Uncomment it if you installed nginx-passenger

## 

#passenger\_root /usr;  
#passenger\_ruby /usr/bin/ruby;

## 

# Virtual Host Configs

## 

include /etc/nginx/conf.d/\*.conf;

# include /etc/nginx/sites-enabled/\*;

include /etc/nginx/cw.conf;  
}

cw.conf:

upstream cwbackend {  
ip\_hash;  
server [cwweb1.domain.com:80](http://cwweb1.domain.com:80);  
server [cwweb2.domain.com:80](http://cwweb2.domain.com:80);  
server [cwweb3.domain.com:80](http://cwweb3.domain.com:80);  
server [cwweb4.domain.com:80](http://cwweb4.domain.com:80);  
keepalive 16;  
}

upstream cwsecure {  
ip\_hash;  
server [cwweb1.domain.com:443](http://cwweb1.domain.com:443);  
server [cwweb2.domain.com:443](http://cwweb2.domain.com:443);  
server [cwweb3.domain.com:443](http://cwweb3.domain.com:443);  
server [cwweb4.domain.com:443](http://cwweb4.domain.com:443);  
keepalive 16;  
}

server {

listen 80;  
server\_name [cw1.domain.com](http://cw1.domain.com);  
client\_max\_body\_size 30M;  
location / {  
proxy\_http\_version 1.1;  
# needed to forward user’s IP address to rails  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header Connection “”;  
# needed for HTTPS  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_set\_header Host $http\_host;  
proxy\_redirect off;  
proxy\_max\_temp\_file\_size 0;  
proxy\_next\_upstream error timeout invalid\_header http\_500;  
proxy\_connect\_timeout 30;  
proxy\_read\_timeout 360;  
proxy\_pass [http://cwbackend](http://cwbackend);

} #end location

} #end server

server {

listen 443;

ssl on;  
ssl\_certificate /usr/local/src/certs-2011-2014/sslchain.crt;  
ssl\_certificate\_key /usr/local/src/certs-2011-2014/domain.com.key;

server\_name [cw1.domain.com](http://cw1.domain.com);  
client\_max\_body\_size 30M;  
location / {  
proxy\_http\_version 1.1;

# needed to forward user’s IP address to rails

```
proxy_set_header X-Real-IP $remote_addr;

# needed for HTTPS
proxy_set_header X-FORWARDED-PROTO https;
proxy_set_header X-FORWARDED-SSL on;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header Connection "";
proxy_redirect off;
proxy_max_temp_file_size 0;
proxy_buffering off;
proxy_connect_timeout 30;
proxy_read_timeout 360;
proxy_pass https://cwsecure;

```

} #end location

} #end server

backend apache2.conf:

LockFile ${APACHE\_LOCK\_DIR}/accept.lock

PidFile ${APACHE\_PID\_FILE}

Timeout 2

KeepAlive On

MaxKeepAliveRequests 100

KeepAliveTimeout 15

 StartServers 5 MinSpareServers 5 MaxSpareServers 10 MaxClients 256 MaxRequestsPerChild 100 StartServers 2 MinSpareThreads 25 MaxSpareThreads 75 ThreadLimit 64 ThreadsPerChild 25 MaxClients 200 MaxRequestsPerChild 0 StartServers 2 MinSpareThreads 25 MaxSpareThreads 75 ThreadLimit 64 ThreadsPerChild 25 MaxClients 150 MaxRequestsPerChild 0

User ${APACHE\_RUN\_USER}  
Group ${APACHE\_RUN\_GROUP}

AccessFileName .htaccess

\<Files ~ “^.ht”\>  
Order allow,deny  
Deny from all  
Satisfy all

DefaultType None

HostnameLookups Off

ErrorLog ${APACHE\_LOG\_DIR}/error.log

LogLevel warn

Include mods-enabled/_.load  
Include mods-enabled/_.conf

Include httpd.conf

Include ports.conf

LogFormat “%v:%p %h %l %u %t "%r" %\>s %O "%{Referer}i"  
"%{User-Agent}i"” vhost\_combined  
LogFormat “%h %l %u %t "%r" %\>s %O "%{Referer}i" "%{User-Agent}i"”  
combined  
LogFormat “%h %l %u %t "%r" %\>s %O” common  
LogFormat “%{Referer}i → %U” referer  
LogFormat “%{User-agent}i” agent

Include conf.d/

Include sites-enabled/

backend site config file:

NameVirtualHost \*:443  
\<VirtualHost \*:443\>  
ServerAdmin removed\_email\_address@domain.invalid  
ServerName [cwweb1.domain.com](http://cwweb1.domain.com)  
SSLEngine On  
SSLCertificateFile /usr/local/src/domain.com.crt  
SSLCertificateKeyFile /usr/local/src/domain.com.key  
SSLCertificateChainFile /usr/local/src/intermediate.crt  
DocumentRoot /data/www  
DirectoryIndex default.php index.php  
  
Options FollowSymLinks  
AllowOverride None  
  
\<Directory /data/www\>  
Options Indexes FollowSymLinks MultiViews  
AllowOverride None  
Order allow,deny  
allow from all

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/  
\<Directory “/usr/lib/cgi-bin”\>  
AllowOverride None  
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch  
Order allow,deny  
Allow from all

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,

# alert, emerg.

LogLevel warn

CustomLog /var/log/apache2/access.log combined  
ServerSignature On

```
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

```

Posted at Nginx Forum:

> **[load balancing random 503](https://forum.nginx.org/read.php?2,230847,230847#msg-230847)**
>
> Hi there I have an instance on ec2 acting as a load balancer for 4 apache2 servers. The instance is ubuntu precise with nginx 1.2.3 The instance has 4 computing units and 3.75 GB memory Everything is working ok, except I get random 503 for some...

---

<div class="post-metadata">

**Author:** ![ihamouda1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c89c15/32.png) [@ihamouda1](https://www.ruby-forum.com/u/ihamouda1)\
**Post date:** [September 22, 2012, 11:22am UTC](https://www.ruby-forum.com/t/load-balancing-random-503/223019/2 "2012-09-22T11:22:11Z")

</div>

Anyone out there to help?

Posted at Nginx Forum:

> **[Re: load balancing random 503](https://forum.nginx.org/read.php?2,230847,230936#msg-230936)**
>
> Hi there I have an instance on ec2 acting as a load balancer for 4 apache2 servers. The instance is ubuntu precise with nginx 1.2.3 The instance has 4 computing units and 3.75 GB memory Everything is working ok, except I get random 503 for some...
