Reputation: 67
Im setting up a load balancer with two docker apache instances on my local network. Both nodes I confirm are up and can view on individual ports 8081 and 8082 but when trying use upstream in apache I get 502 bad gateway error.
I have tried changing permissions on /etc/nginx directory to nginx user. I have tried restarting apache instances and nginx service. When I change server_name to localhost instead of ip address of the server host then I can see default nginx server page on my web browser from another machine on my local network. If I change it back to IP address I get the bad gateway error.
I have my default.conf symlinked to sites-available
[root@www nginx]# vi sites-enabled/default.conf
upstream containerapp {
server 192.168.0.42:8081;
server 192.168.0.42:8082;
}
server {
listen *:80;
server_name localhost;
index index.html index.htm index.php;
access_log /var/log/nginx/localweb.log;
error_log /var/log/nginx/localerr.log;
location /{
proxy_pass http://containerapp;
}
}
This is the log file error I get
[root@www nginx]# cat /var/log/nginx/localerr.log
referrer: "http://192.168.0.42/"
2019/01/04 20:15:54 [error] 16310#0: *1 no live upstreams while
connecting
to upstream, client: 192.168.0.18, server: 192.168.0.42, request:
"GET / HTTP/1.1", upstream: "http://containerapp/",
host:"192.168.0.42"
2019/01/04 20:15:54 [error] 16310#0: *1 no live upstreams while
connecting
to upstream, client: 192.168.0.18, server: 192.168.0.42, request:
"GET
/favicon.ico HTTP/1.1", upstream: "http://containerapp/favicon.ico",
host:
"192.168.0.42", referrer: "http://192.168.0.42/"
This is how my nginx.conf looks
nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local]
"$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d
directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
#include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
#include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
include /etc/nginx/sites-enabled/*;
}
I can hit http://192.168.0.42 and it will direct round robin to http://192.168.0.42:8081 or http://192.168.0.42:8082 nodes
Upvotes: 1
Views: 8104
Reputation: 67
I found the solution to this was selinux related. There was another post here I found with this command
setsebool -P httpd_can_network_connect 1
link to the original question in case anyone has this problem in future (13: Permission denied) while connecting to upstream:[nginx]
Upvotes: 2
Reputation: 59
In my opinion this is problem with slow response from apache instance.
This will be help:
location /{
proxy_pass http://containerapp;
proxy_read_timeout 5m;
}
Upvotes: 0