Image 01 Image 02

User profile

Estado:
Nombre: smcnally
Nickname: smcnally
Miembro desde: 2009-03-31 19:54:09
URL:
Sobre mi:
 

User comments

Load Balancing with Nginx

Thanks for the article, Sameer.

I’ve read this and your nginx setup article.

I’m shooting for a slightly different config: nginx behaves solely as a load balancer. apache2 is serving all static and dynamic content. (it’s running wordpress mu, in fact).

I’m not sure what my nginx.conf looks like in total.

So far, this is what I have - it’s not yet working as I’d hoped (i.e. passing all http requests through to one or more of the apache2 servers). Any direction and assistance you can provide is greatly appreciated.

user www-data;
worker_processes 1;

error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
upstream www-cluster {
ip_hash;
server 000.20.000.108:80; # ts-www0
server 000.20.000.000:80; # ts-www1
server 000.20.000.000:80; # ts-www2
}
}

my actual public ips are in the server entries.

Many thanks, and please let me know if there’s other info I can provide to assist in troubleshooting

Load Balancing with Nginx

Hello -

A few differences - and the source of my confusion - are on the following directives:

server {
listen 80;

I’ve got apache on port 80, so I presume nginx out to be listening on another port. True statement?

# static files
location ~* ^.+.(jpg|jpeg|gif|png|ico|css|txt|js|htm|html)$ {
root /path/to/webroot;
}

I don’t plan to serve any content directly via nginx. I’ve commented this section out.

# pass all else onto apache waiting at localhost:8080
location / {
proxy_pass http://localhost:8080;

so, here’s where I presumed to add my ip_hash of servers:

My update:

# pass all else onto apache waiting :80
location / {
proxy_pass http {
upstream www-cluster {
ip_hash;
server 000.20.86.000:80; # ts-www0
server 000.20.86.000:80; # ts-www1
server 000.20.87.000:80; # ts-www2

Am I on the correct path?

Again, I appreciate your time and assistance a great deal.

Load Balancing with Nginx

Thank you, again, Sameer -
nginx and apache are on different physical hosts. Both listening on port 80.

nginx is still fulfilling requests I presumed it would be passing along.

I’m seeing nothing in the logs or from the clients (workstation web browser) to say anything’s going beyond nginx’ default config:

http://209.20.83.83/

173.68.142.30 - - [01/Apr/2009:02:42:15 +0000] “GET / HTTP/1.1″ 304 0 “-” “Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/528.16 (KHTML, like Gecko) Version/4.0 Safari/528.16″

I’m sure I’m missing something simple.

smcnally@lb1:/var/log/nginx$ sudo cat /etc/nginx/nginx.conf
[sudo] password for smcnally:
user www-data www-data;
worker_processes 1;

error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

access_log /var/log/nginx/access.log;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;

gzip on;

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

# this is where you define your mongrel clusters.
# you need one of these blocks for each cluster
# and each one needs its own name to refer to it later.
upstream stag-ts {
ip_hash;
server 209.20.86.108:80; # ts-www0
server 209.20.86.117:80; # ts-www1
server 209.20.87.81:80; # ts-www2
}

server {
listen 80;
server_name http://stage.authorified.com;
location / {
proxy_pass http://stag-ts;
}
}

}

My goal is to pass all requests to one of the apache2 nodes. Apache logfiles show nothing.

Requesting the IP or domain name via browser client passes nothing to www0 - www2.

I’m fronting a different physical boxes (x3) for apache. Those refer to a different physical box for mysql.

The goal is for requests to http://209.20.83.83/ to be distributed to

server 209.20.86.108:80; # ts-www0
server 209.20.86.117:80; # ts-www1
server 209.20.87.81:80; # ts-www2

I would have private messaged, but did not see that option. With hope, all can learn.

Many thanks, best regards, and please let me know what *stupid* thing I’m doing.

S