apache - 502 Bad Gateway nginx/1.11.5 在 docker 中运行

标签 apache nginx docker cxf gateway

我在 Apache Karaf 中运行 soap Web 服务,我们使用的是 Apache CXF 2.7.6,JDK 是 1.7.0_80。我在 Centos 7 下的 Oracle VM Virtual box 上的笔记本电脑上的 docker 容器中运行以下命令

  • MongoDB
  • ActiveMQ
  • BlazeDS
  • HTTPD
  • OpenLDAP
  • NGINX
  • 关系

Apache Flex 中的 UI 调用以下 url 进行登录,我们收到以下错误:

http://my_virtual_machine_ip_address/usermanagementcxf/UserManagementService?wsdl结果从 Nginx 进入 502 Bad Gateway

在这里,请注意 Nginx 在 docker 内部运行,而托管 soap 服务的 Apache Karaf 不是在 docker 内部而是在 docker 外部运行,基本上是在本地运行。

能否请您告诉我在这里可以做些什么来解决这个问题?非常感谢这方面的任何帮助。

我还尝试了以下方法来解决这个问题:

  • 重启 Nginx、httpd 和 blazeds
  • setsebool -P httpd_can_network_connect true
  • setsebool -P httpd_can_network_relay 1
  • 重启 Centos 7 操作系统

nginx.conf

root@a16807c2c955:/etc/nginx# cat nginx.conf 

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
include       /etc/nginx/mime.types;
default_type  application/octet-stream;

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;

#gzip  on;

#include /etc/nginx/conf.d/*.conf;

server {
listen  80 default_server;
listen  [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;

include /etc/nginx/default.d/*.conf;

    location / {
    }



}
}

我的应用程序.conf

    root@a16807c2c955:/etc/nginx/default.d# cat myapplication.conf 
    resolver 127.0.0.1;

    location /crossdomain.xml {
        proxy_pass      http://ls-httpd:8079/crossdomain.xml;
    }

        location /blazeds/ {
            proxy_pass      http://ls-blazeds:8089/blazeds/;

            proxy_set_header    Host        $host;
            proxy_set_header    X-Real-IP   $remote_addr;

            error_log       /var/log/nginx/blazeds.error.log;
            access_log      /var/log/nginx/blazeds.access.log;
        }

    location /myapplicationcxf/ {
        proxy_pass      http://ls-services:8080/cxf/;
        error_log       /var/log/nginx/myapplication.error.log;
        access_log      /var/log/nginx/myapplication.access.log;
    }

    location /usermanagementcxf/ {
        proxy_pass      http://ls-services:8080/cxf/;
        error_log       /var/log/nginx/usermanagement.error.log;
        access_log      /var/log/nginx/usermanagement.access.log;
    }

    location /myapplicationtestcxf/ {
        proxy_pass      http://ls-services:8080/cxf/;
        error_log       /var/log/nginx/myapplicationtestcxf.error.log;
        access_log      /var/log/nginx/myapplicationtestcxf.access.log;
    }

    location /myapplicationadapt/ {
        proxy_pass      http://ls-httpd:8079/assets/;
        error_log       /var/log/nginx/myapplicationadapt.error.log;
        access_log      /var/log/nginx/myapplicationadapt.access.log;
    }

    location /myapplicationreports/ {
        proxy_pass      http://ls-httpd:8083/jasperreportpublisher/;
        error_log       /var/log/nginx/myapplicationreports.error.log;
        access_log      /var/log/nginx/myapplicationreports.access.log;
    }

    location /appname/ {
        proxy_pass      http://ls-httpd:8079/;
        error_log       /var/log/nginx/appnameapp.error.log;
        access_log      /var/log/nginx/appnameapp.access.log;
    }
    location /appname {
        proxy_pass      http://ls-httpd:8079/;
        error_log       /var/log/nginx/appnameapp.error.log;
        access_log      /var/log/nginx/appnameapp.access.log;
    }

    location /APPNAME/ {
        proxy_pass      http://ls-httpd:8079/;
        error_log       /var/log/nginx/appnameapp.error.log;
        access_log      /var/log/nginx/appnameapp.access.log;
    }
    location /APPNAME {
        proxy_pass      http://ls-httpd:8079/;
        error_log       /var/log/nginx/appnameapp.error.log;
        access_log      /var/log/nginx/appnameapp.access.log;
    }

    location /appnameapp/ {
        proxy_pass      http://ls-httpd:8079/;
        error_log       /var/log/nginx/appnameapp.error.log;
        access_log      /var/log/nginx/appnameapp.access.log;
    }

    location /myapplication/ {
        proxy_pass      http://ls-httpd:8079/;
        error_log       /var/log/nginx/appnameapp.error.log;
        access_log      /var/log/nginx/appnameapp.access.log;
    }
    location /myapplication {
        proxy_pass      http://ls-httpd:8079/;
        error_log       /var/log/nginx/appnameapp.error.log;
        access_log      /var/log/nginx/appnameapp.access.log;
    }

    location /Myapplication/ {
        proxy_pass      http://ls-httpd:8079/;
        error_log       /var/log/nginx/appnameapp.error.log;
        access_log      /var/log/nginx/appnameapp.access.log;
    }
    location /Myapplication {
        proxy_pass      http://ls-httpd:8079/;
        error_log       /var/log/nginx/appnameapp.error.log;
        access_log      /var/log/nginx/appnameapp.access.log;
    }

/etc/hosts 文件

[root@myhostname apache-karaf-2.3.3]# cat /etc/hosts
my_virtual_machine_ip_address ls-blazeds
my_virtual_machine_ip_address ls-services
my_virtual_machine_ip_address ls-mongo
my_virtual_machine_ip_address ls-activemq ls-queue01 ls-queue02
my_virtual_machine_ip_address ls-httpd
my_virtual_machine_ip_address ls-ldap
my_virtual_machine_ip_address ls-nginx
my_virtual_machine_ip_address myhostname
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 myhostname
::1       localhost localhost.localdomain localhost6 localhost6.localdomain6

各种日志文件

root@fca3d332c76b:/var/log/nginx# tail -f access.log     
172.17.0.1 - - [02/Dec/2016:12:54:00 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0" "-"
172.17.0.1 - - [02/Dec/2016:12:54:00 +0000] "GET /favicon.ico HTTP/1.1" 404 169 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0" "-"
172.17.0.1 - - [02/Dec/2016:13:06:54 +0000] "GET /favicon.ico HTTP/1.1" 404 169 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0" "-"
172.17.0.1 - - [02/Dec/2016:13:06:54 +0000] "GET /favicon.ico HTTP/1.1" 404 169 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0" "-"
172.17.0.1 - - [02/Dec/2016:13:07:00 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0" "-"
172.17.0.1 - - [02/Dec/2016:14:54:33 +0000] "GET /favicon.ico HTTP/1.1" 404 169 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0" "-"
172.17.0.1 - - [02/Dec/2016:14:54:35 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0" "-"
10.0.2.15 - - [02/Dec/2016:14:54:41 +0000] "GET /favicon.ico HTTP/1.1" 404 169 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0" "-"
172.17.0.1 - - [02/Dec/2016:14:55:17 +0000] "GET /favicon.ico HTTP/1.1" 404 169 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0" "-"
172.17.0.1 - - [02/Dec/2016:14:55:29 +0000] "GET /favicon.ico HTTP/1.1" 404 169 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0" "-"
^C
root@fca3d332c76b:/var/log/nginx# tail -f error.log  
2016/12/02 14:54:33 [error] 9#9: *5 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 172.17.0.1, server: _, request: "GET /favicon.ico HTTP/1.1", host: "localhost"
2016/12/02 14:54:41 [error] 9#9: *7 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 10.0.2.15, server: _, request: "GET /favicon.ico HTTP/1.1", host: "10.0.2.15"
2016/12/02 14:55:17 [error] 9#9: *10 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 172.17.0.1, server: _, request: "GET /favicon.ico HTTP/1.1", host: "172.17.0.8"
2016/12/02 14:55:29 [error] 9#9: *13 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 172.17.0.1, server: _, request: "GET /favicon.ico HTTP/1.1", host: "172.17.0.1"
^C
root@fca3d332c76b:/var/log/nginx# tail -f usermanagement.access.log 
10.0.2.15 - - [02/Dec/2016:14:49:50 +0000] "GET /usermanagementcxf/UserManagementService?wsdl HTTP/1.1" 502 173 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
10.0.2.15 - - [02/Dec/2016:14:54:14 +0000] "GET /usermanagementcxf/UserManagementService?wsdl HTTP/1.1" 502 173 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
10.0.2.15 - - [02/Dec/2016:14:54:17 +0000] "GET /usermanagementcxf/UserManagementService?wsdl HTTP/1.1" 502 173 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
10.0.2.15 - - [02/Dec/2016:14:54:41 +0000] "GET /usermanagementcxf/UserManagementService?wsdl HTTP/1.1" 502 173 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
172.17.0.1 - - [02/Dec/2016:14:55:17 +0000] "GET /usermanagementcxf/UserManagementService?wsdl HTTP/1.1" 502 173 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
172.17.0.1 - - [02/Dec/2016:14:55:29 +0000] "GET /usermanagementcxf/UserManagementService?wsdl HTTP/1.1" 502 173 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
10.0.2.15 - - [02/Dec/2016:14:55:37 +0000] "GET /usermanagementcxf/UserManagementService?wsdl HTTP/1.1" 502 173 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
10.0.2.15 - - [02/Dec/2016:14:55:51 +0000] "GET /usermanagementcxf/UserManagementService?wsdl HTTP/1.1" 502 173 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
172.17.0.1 - - [02/Dec/2016:14:56:02 +0000] "GET /usermanagementcxf/UserManagementService?wsdl HTTP/1.1" 502 173 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
10.0.2.15 - - [02/Dec/2016:14:56:07 +0000] "GET /usermanagementcxf/UserManagementService?wsdl HTTP/1.1" 502 173 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
^C
root@fca3d332c76b:/var/log/nginx# tail -f usermanagement.error.log  
2016/12/05 11:06:14 [error] 7#7: *25 connect() failed (113: No route to host) while connecting to upstream, client: 10.0.2.15, server: _, request: "GET /usermanagementcxf/UserManagementService?wsdl HTTP/1.1", upstream: "http://10.0.2.15:8080/cxf/UserManagementService?wsdl", host: "10.0.2.15"
2016/12/05 11:37:06 [error] 7#7: *1 connect() failed (113: No route to host) while connecting to upstream, client: 10.0.2.15, server: _, request: "GET /usermanagementcxf/UserManagementService?wsdl HTTP/1.1", upstream: "http://10.0.2.15:8080/cxf/UserManagementService?wsdl", host: "10.0.2.15"
2016/12/05 13:30:13 [error] 10#10: *4 connect() failed (113: No route to host) while connecting to upstream, client: 10.0.2.15, server: _, request: "GET /usermanagementcxf/UserManagementService?wsdl HTTP/1.1", upstream: "http://10.0.2.15:8080/cxf/UserManagementService?wsdl", host: "10.0.2.15"

docker 检查网桥

[username@myhostname nginx]# docker network inspect bridge
[
    {
        "Name": "bridge",
        "Id": "9d6b9700358b5c79e27a29d700c8a6a71e07d15552106901fad6630e9bafdd23",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16",
                    "Gateway": "172.17.0.1"
                }
            ]
        },
        "Internal": false,
        "Containers": {
            "18ab8f790aa52111184ce6fd83b22e3c09b89116502dd631a1357ba7f094277c": {
                "Name": "ls-mongo",
                "EndpointID": "9f0cf2d66909316396af4cee466f21ee2b9e5f82eee6e822c4ebab8422910cae",
                "MacAddress": "02:42:ac:11:00:06",
                "IPv4Address": "172.17.0.6/16",
                "IPv6Address": ""
            },
            "24c98a655fecd973f5be8dbd92f3be4b85d7b3516c5e8808fceab3e37f527f4a": {
                "Name": "ls-blazeds",
                "EndpointID": "bc2002dbbdf38703bf2f0b46cf16c28e0f2c12d7ca64dc22070c0723c90ddff3",
                "MacAddress": "02:42:ac:11:00:08",
                "IPv4Address": "172.17.0.8/16",
                "IPv6Address": ""
            },
            "918d4a4e1dba370f4b232b4e19bb2d6c7e894aea24d96e6fd960a717d8d6001d": {
                "Name": "ls-activemq",
                "EndpointID": "eeb75d2f1b18e9076d8d03a982c349072d32ec8bbcdba0d573270468121c5518",
                "MacAddress": "02:42:ac:11:00:07",
                "IPv4Address": "172.17.0.7/16",
                "IPv6Address": ""
            },
            "93b1bcb9c2d1720f246b212e613ccd1b12f36b078637413147f09d5414302354": {
                "Name": "ls-httpd",
                "EndpointID": "3e910a7c354a4db935d6cf0a7457ba0c81e08492041e912108eda103e644454d",
                "MacAddress": "02:42:ac:11:00:03",
                "IPv4Address": "172.17.0.3/16",
                "IPv6Address": ""
            },
            "a16807c2c955be35340c7f64f96c100904704e9fee40ca7c7737bcb358972636": {
                "Name": "ls-nginx",
                "EndpointID": "3ebce575049d46101ed50f217d0a61c2ad51a36dca33340cbcef09b00374536c",
                "MacAddress": "02:42:ac:11:00:04",
                "IPv4Address": "172.17.0.4/16",
                "IPv6Address": ""
            },
            "e1ecc4ac677d7749fb18e78492941d64a71fb80448026f5abf86e70316f3295a": {
                "Name": "nexus",
                "EndpointID": "e3bfa1ab5427636709bddae75a3b7d45f8fb9e80410149f402ed597d18677b92",
                "MacAddress": "02:42:ac:11:00:02",
                "IPv4Address": "172.17.0.2/16",
                "IPv6Address": ""
            },
            "f8efa4cb1a28b25895fbf6538c7fa02a0990cf28b8822056e82edbaf13975350": {
                "Name": "ls-ldap",
                "EndpointID": "b0388b3e1f242efdd11bd51e0bf8e31ffb609075583cbea5744a7c3d629f4cbd",
                "MacAddress": "02:42:ac:11:00:05",
                "IPv4Address": "172.17.0.5/16",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.bridge.default_bridge": "true",
            "com.docker.network.bridge.enable_icc": "true",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
            "com.docker.network.bridge.name": "docker0",
            "com.docker.network.driver.mtu": "1500"
        },
        "Labels": {}
    }
]

flashlogs - UI 端

12/1/2016 17:38:29.225 [DEBUG] mx.messaging.Channel 'direct_http_channel' channel sending message:
(mx.messaging.messages::HTTPRequestMessage)#0
  body = (Object)#1
  clientId = (null)
  contentType = "application/x-www-form-urlencoded"
  destination = "DefaultHTTP"
  headers = (Object)#2
    DSRemoteCredentials = ""
    DSRemoteCredentialsCharset = (null)
  httpHeaders = (null)
  messageId = "276C2438-DEED-3F9F-5567-BB7752E70224"
  method = "GET"
  recordHeaders = false
  timestamp = 0
  timeToLive = 0
  url = "http://my_virtual_machine_ip_address/usermanagementcxf/UserManagementService?"
Warning: HTTP send request error, 12029: /ramplogicadapt/phpFunctions.php
12/1/2016 17:39:11.278 [INFO] mx.messaging.Producer '2304C2EF-FB83-9438-B164-BB7750A0E460' producer acknowledge of 'BAA0601B-0DDD-3FC3-DC17-BB775286490D'.
12/1/2016 17:39:11.281 [ERROR] mx.messaging.Producer '2304C2EF-FB83-9438-B164-BB7750A0E460' producer fault for 'BAA0601B-0DDD-3FC3-DC17-BB775286490D'.
Warning: HTTP send request error, 12029: /usermanagementcxf/UserManagementService?wsdl
12/1/2016 17:39:32.276 [INFO] mx.messaging.Producer '1D4C4F2A-BB9B-28FB-63B1-BB7752DF95B3' producer acknowledge of '276C2438-DEED-3F9F-5567-BB7752E70224'.
12/1/2016 17:39:32.280 [ERROR] mx.messaging.Producer '1D4C4F2A-BB9B-28FB-63B1-BB7752DF95B3' producer fault for '276C2438-DEED-3F9F-5567-BB7752E70224'.
Warning: HTTP send request error, 12002: /usermanagementcxf/UserManagementService?wsdl
12/1/2016 17:39:32.294 [INFO] mx.messaging.Producer 'DDAE8934-5315-F289-CF40-BB7752BCEE4C' producer acknowledge of 'CAC9A8B2-CF6D-3697-03EA-BB7752CF2FB6'.
12/1/2016 17:39:32.295 [ERROR] mx.messaging.Producer 'DDAE8934-5315-F289-CF40-BB7752BCEE4C' producer fault for 'CAC9A8B2-CF6D-3697-03EA-BB7752CF2FB6'.
12/1/2016 17:39:47.598 [DEBUG] mx.rpc.soap.Operation Queueing SOAP operation authenticateAndRegisterLogin

最佳答案

以下对我有用。如果您正在使用由 docker 创建并命名为 docker0 的以太网桥,您可以通过以 root 身份运行以下命令来设置以下转发规则:

  1. iptables -A FORWARD -i docker0 -o eth0 -j ACCEPT
  2. iptables -A FORWARD -i eth0 -o docker0 -j ACCEPT
  3. iptables -I 输入 1 -i docker0 -j 接受
  4. iptables-保存
  5. reboot命令重启机器

引用: https://fralef.me/docker-and-iptables.html

https://unix.stackexchange.com/questions/178829/docker-container-not-able-to-ping-host

https://github.com/docker/docker/issues/24370

iptables rules break communication between Docker containers

关于apache - 502 Bad Gateway nginx/1.11.5 在 docker 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40958715/

相关文章:

apache - 适合初学者的好 apache http 服务器教程

r - R工具是否与apache hadoop兼容

php - Nginx PHP 因大文件上传(超过 6 GB)而失败

Nginx 获取事件 "ngx_master_****"5 秒未发出信号

python - 由于缺少编译器错误,带有 python 和 alpine 的 Docker 镜像失败

python - 在 Django 中使用 mod_wsgi 找不到请求的 URL

Java Apache HttpPost、setEntity 替换或追加

node.js - socket.io 什么时候使用轮询而不是 websockets?

azure - 如何通过 ARM 模板设置 Azure Batch 池容器配置?

docker - 如何批量删除特定的正在运行的Docker容器