Remova o http { .. }
e tenha isso dentro de seu /etc/nginx/sites-available/default
:
upstream myapp1 {
server 192.168.0.20;
}
server {
listen 80;
location / {
proxy_pass http://myapp1;
}
}
Eu tenho um sistema Ubuntu funcionando como um balanceador de carga e o /etc/nginx/sites-available/default
se parece com isso:
http {
upstream myapp1 {
server 192.168.0.20:80;
}
server {
listen 80;
location / {
proxy_pass http://myapp1;
}
}
}
No dispositivo com o endereço IP 192.168.0.20
, configurei um comando para ouvir todas as conexões de entrada da porta 80
sudo tcpdump -n -tttt -i eth0 port 80
Mas ao acessar o balanceador de carga através da porta 80, nada é captado por 192.168.0.20
de quaisquer ideias de porque isso está acontecendo?
E o /etc/nginx/sites-available/default
para 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;
}
}
Isso é o que o curl -v 192.168.0.20
retorna quando eu o executo no 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
Então, se eu alterar meu /etc/nginx/sites-available/default
no LB para:
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;
}
}
funciona, mas isso não está realmente dando a opção de adicionar mais ao cluster?
Tags nginx load-balancing ubuntu