尝试获取 Scala 应用程序时 connect() 失败(111:连接被拒绝)

尝试获取 Scala 应用程序时 connect() 失败(111:连接被拒绝)

我正在尝试运行一个正在监听端口 9000 的 scala 应用程序,我已经设置了 nginx 来监听这个端口,但似乎有些不对劲,

curl: (7) Failed to connect to localhost port 9000: Connection refused
[vagrant@localhost ~]$ curl localhost
<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.14.1</center>
</body>
</html>

2021/02/27 03:08:52 [error] 3289#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: 0.0.0.0, request: "GET / HTTP/1.1", upstream: "http://0.0.0.0:9000/", host: "localhost"
    2021/02/27 03:08:55 [error] 3289#0: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: 0.0.0.0, request: "GET / HTTP/1.1", upstream: "http://0.0.0.0:9000/", host: "localhost"
    2021/02/27 03:08:56 [error] 3289#0: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: 0.0.0.0, request: "GET / HTTP/1.1", upstream: "http://0.0.0.0:9000/", host: "localhost"
    2021/02/27 03:08:57 [error] 3289#0: *7 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: 0.0.0.0, request: "GET / HTTP/1.1", upstream: "http://0.0.0.0:9000/", host: "localhost"
    2021/02/27 03:15:53 [error] 3289#0: *9 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: 0.0.0.0, request: "GET / HTTP/1.1", upstream: "http://0.0.0.0:9000/", host: "localhost"
    2021/02/27 03:16:02 [error] 3289#0: *11 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: 0.0.0.0, request: "GET / HTTP/1.1", upstream: "http://0.0.0.0:9000/", host: "localhost"

我的nginx.config文件看起来像这样

    worker_processes  1;

events {
    worker_connections  1024;
}

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

  sendfile        on;
  keepalive_timeout  65;

  proxy_buffering    off;
  proxy_set_header   X-Real-IP $remote_addr;
  proxy_set_header   X-Forwarded-Proto $scheme;
  proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header   Host $http_host;
  proxy_http_version 1.1;

  upstream my-backend {
     server 0.0.0.0:9000;
  }

  server {
    listen       80;
    server_name  0.0.0.0;
    location / {
       proxy_pass http://my-backend;
    }
  }

}

应用程序日志和端口监听

        at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:111)
        at com.google.inject.Guice.createInjector(Guice.java:87)
        at com.google.inject.Guice.createInjector(Guice.java:78)
        at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:200)
        at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:155)
        at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
        at play.core.server.ProdServerStart$.start(ProdServerStart.scala:54)
        at play.core.server.ProdServerStart$.main(ProdServerStart.scala:30)
        at play.core.server.ProdServerStart.main(ProdServerStart.scala)
Caused by: org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
        at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:270)
        at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:67)
        at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:212)
        at org.postgresql.Driver.makeConnection(Driver.java:407)
        at org.postgresql.Driver.connect(Driver.java:275)
        at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136)
        at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369)
        at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198)
        at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467)
        at com.zaxxer.hikari.pool.HikariPool.access$100(HikariPool.java:71)
        at com.zaxxer.hikari.pool.HikariPool$PoolEntryCreator.call(HikariPool.java:706)
        at com.zaxxer.hikari.pool.HikariPool$PoolEntryCreator.call(HikariPool.java:692)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.ConnectException: Connection refused (Connection refused)
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:607)
        at org.postgresql.core.PGStream.<init>(PGStream.java:64)
        at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:150)
        ... 15 more
[vagrant@localhost cookbooks]$ ss -lntp | grep 9000
[vagrant@localhost cookbooks]$ ss -lntp | grep 80
LISTEN    0         128                0.0.0.0:80               0.0.0.0:*
LISTEN    0         128                   [::]:80                  [::]:*
[vagrant@localhost cookbooks]$ ss -lntp | grep 9000
[vagrant@localhost cookbooks]$

答案1

您需要将行0.0.0.0中的替换为 scala 应用程序正在监听的 IP 地址或主机名。 即使它正在监听接口(),您也不能在该行上使用 0.0.0.0。在这种情况下 ,您可以使用环回接口(或)。servernginx.config
any0.0.0.0server
localhost127.0.0.1

您的 scala 应用程序实际上可能正在监听端口 9000,但它可能绑定到外部网络接口(eth0wlan0p2p1其他,取决于硬件和 Linux 发行版)而不是接口any0.0.0.0)。
在这种情况下,您必须使用它正在监听的地址,而不是环回地址 127.0.0.1。

您可以使用@berndbausch 指出的fuser 9000/tcp某些等效lsof命令来找到 scala 应用程序的列表地址。ss

相关内容