AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 770082
Accepted
lopar
lopar
Asked: 2016-04-14 07:55:15 +0800 CST2016-04-14 07:55:15 +0800 CST 2016-04-14 07:55:15 +0800 CST

Nginx 上游返回«站点不可用»,而他们工作

  • 772

我使用upstreamandproxy进行负载平衡。

[[email protected] ~]# cat /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    upstream sites {
        server 192.168.1.237:8080;
        server 192.168.1.240:8080;
    }
    server {
        listen       80 default_server;
        listen       [::]:80 default_server;

        server_name  _;
        root         /usr/share/nginx/html;
        include /etc/nginx/default.d/*.conf;

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

当我在浏览器中打开 192.168.1.135 时,它告诉我,«网站暂时不可用»。

来自 192.168.1.135 的所有 ping 均正常工作:

PING 192.168.1.237 (192.168.1.237) 56(84) bytes of data.
64 bytes from 192.168.1.237: icmp_seq=1 ttl=64 time=0.803 ms
64 bytes from 192.168.1.237: icmp_seq=2 ttl=64 time=0.329 ms
64 bytes from 192.168.1.237: icmp_seq=3 ttl=64 time=0.676 ms
64 bytes from 192.168.1.237: icmp_seq=4 ttl=64 time=0.579 ms

PING 192.168.1.240 (192.168.1.240) 56(84) bytes of data.
64 bytes from 192.168.1.240: icmp_seq=1 ttl=64 time=0.607 ms
64 bytes from 192.168.1.240: icmp_seq=2 ttl=64 time=0.264 ms
64 bytes from 192.168.1.240: icmp_seq=3 ttl=64 time=0.358 ms
64 bytes from 192.168.1.240: icmp_seq=4 ttl=64 time=0.253 ms

当我将浏览器指向http://192.168.1.237:8080或http://192.168.1.240:8080时,它们会成功打开。

nginx 错误日志

2016/04/13 18:36:59 [crit] 5427#0: *20 connect() to 192.168.1.240:8080 failed (13: Permission denied) while connecting to upstream, client: 192.168.1.15, server: _, request: "GET / HTTP/1.1", upstream: "http://192.168.1.240:8080/", host: "192.168.1.135"
2016/04/13 18:36:59 [crit] 5427#0: *20 connect() to 192.168.1.237:8080 failed (13: Permission denied) while connecting to upstream, client: 192.168.1.15, server: _, request: "GET / HTTP/1.1", upstream: "http://192.168.1.237:8080/", host: "192.168.1.135"

什么地方出了错?谢谢你。

load-balancing nginx
  • 1 1 个回答
  • 172 Views

1 个回答

  • Voted
  1. Best Answer
    lopar
    2016-04-22T00:03:35+08:002016-04-22T00:03:35+08:00

    工作配置部分:

    location / {
       proxy_pass http://sites;
       proxy_redirect http://192.168.1.135:8080 http://192.168.1.135;
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    

    如果 SELinux 的问题不会消失,您需要打开httpd_can_network_connect指令:

    # sudo setsebool httpd_can_network_connect on -P
    
    • 0

相关问题

  • 网络负载平衡服务器无法相互通信

  • 用于网络监控的路由/代理 SNMP 陷阱(或 Netflow、通用 UDP 等)的解决方案?

  • 防止拒绝服务攻击的最佳技术是什么?

  • 添加备份互联网连接需要哪些硬件?

  • 什么是最有效的 Windows 负载平衡解决方案?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve