【发布时间】:2019-05-31 10:22:57
【问题描述】:
我在本地网络上设置了一个带有两个 docker apache 实例的负载均衡器。我确认的两个节点都已启动,并且可以在单个端口 8081 和 8082 上查看,但是当尝试在 apache 中使用上游时,我得到 502 bad gateway 错误。
我尝试将 /etc/nginx 目录的权限更改为 nginx 用户。我尝试重新启动 apache 实例和 nginx 服务。当我将 server_name 更改为 localhost 而不是服务器主机的 ip 地址时,我可以在我的本地网络上的另一台机器上的 Web 浏览器上看到默认的 nginx 服务器页面。如果我将它改回 IP 地址,我会收到错误的网关错误。
我的 default.conf 符号链接到可用站点
[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;
}
}
这是我得到的日志文件错误
[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/"
这就是我的 nginx.conf 的样子
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/*;
}
我可以点击http://192.168.0.42,它会将循环引导到http://192.168.0.42:8081 或http://192.168.0.42:8082 节点
【问题讨论】:
标签: nginx