4

I have an ubuntu system working as a load balancer and the /etc/nginx/sites-available/default looks like this:

http {
    upstream myapp1 {
        server 192.168.0.20:80;
    }

    server {
        listen 80;

        location / {
            proxy_pass http://myapp1;
        }
    }
}

On the device with the IP address 192.168.0.20 I have set up a command to listen to all port 80 incoming connections

sudo tcpdump -n -tttt -i eth0 port 80

But when accessing the load balancer through port 80 nothing is picked up by 192.168.0.20 any ideas why this is hapenning?

And the /etc/nginx/sites-available/default for 192.168.0.20:

server {
    listen 80 default_server;
    #listen [::]:80 default_server ipv6only=on;

    root /var/www;
    index index.php index.html index.htm;

    server_name 192.168.0.20;

    location / {
        try_files $uri $uri/ =404;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

edit for s3v3n

This is what curl -v 192.168.0.20 returns when I run it on the LB:

* Rebuilt URL to: 192.168.0.20/
* Hostname was NOT found in DNS cache
*   Trying 192.168.0.20...
* Connected to 192.168.0.20 (192.168.0.20) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 192.168.0.20
> Accept: */*
> 
< HTTP/1.1 200 OK
* Server nginx/1.2.1 is not blacklisted
< Server: nginx/1.2.1
< Date: Fri, 13 Mar 2015 14:26:13 GMT
< Content-Type: text/html
< Content-Length: 344
< Last-Modified: Fri, 13 Mar 2015 14:25:58 GMT
< Connection: keep-alive
< Accept-Ranges: bytes
< 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Load balancing set up!</title>
</head>

<body>
Success! You have set it up!!
</body>
</html>

* Connection #0 to host 192.168.0.20 left intact

So if I change my /etc/nginx/sites-available/default on the LB to:

server {

    listen 80;
    server_name 192.168.0.20;

    location / {
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass http://192.168.0.20;
    }
}

it works but that is not really giving the option to add more to the cluster?

5
  • What is the complete nginx configuration? This virtual host might not be the default virtual host, if there are other virtual hosts defined. Mar 12, 2015 at 20:51
  • please see the update. There are no other virtual hosts!
    – maxisme
    Mar 12, 2015 at 21:09
  • Is 192.168.0.20 accessible from the host the load balancer is on? Try curl -v 192.168.0.20.
    – s3v3n
    Mar 12, 2015 at 21:13
  • Have you linked the configuration file to /etc/nginx/sites-enabled directory? Mar 12, 2015 at 21:37
  • @s3v3n please see me edit!!
    – maxisme
    Mar 13, 2015 at 14:21

1 Answer 1

2

Remove the http { .. } and just have this inside your /etc/nginx/sites-available/default:

upstream myapp1 {
    server 192.168.0.20;
}

server {
    listen 80;

    location / {
        proxy_pass http://myapp1;
    }
}
3
  • Please see edited question!
    – maxisme
    Mar 13, 2015 at 15:03
  • 1
    @Maximilian, just a guess, but do you really need the http { .. } block? I don't have any in my default config. Try the initial configuration but skip the http block - use just the contents.
    – s3v3n
    Mar 13, 2015 at 15:56
  • 1
    It is strange that all the tutorials I have seen have it included! Maybe it is incase more stuff is going on outside other than redirects!
    – maxisme
    Mar 14, 2015 at 11:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .