【问题标题】:Springboot application on HerokuHeroku 上的 Spring Boot 应用程序
【发布时间】:2018-09-24 02:32:48
【问题描述】:

我正在尝试在 Heroku 上部署 Spring Boot 应用程序,它在应用程序部署后抛出以下错误。

2018-04-13T16:47:42.573257Z system[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2018-04-13T16:47:42.573323Z system[web.1]: Stopping process with SIGTERM
2018-04-13T16:47:42.5788Z app[web.1]: 2018-04-13 16:47:42.577  INFO 26 --- [       Thread-3] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@75a1cd57: startup date [Fri Apr 13 16:46:43 UTC 2018]; root of context hierarchy
2018-04-13T16:47:42.585423Z app[web.1]: 2018-04-13 16:47:42.585  INFO 26 --- [       Thread-3] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown
2018-04-13T16:47:43.574239Z system[web.1]: Process exited (exit status 143)
2018-04-13T16:47:43.596277+00:00 system[web.1]: State changed from starting to crashed

以下日志表明在 proc 文件中手动提供的端口 8085 上部署成功

2018-04-13T16:46:47.276958Z app[web.1]: 2018-04-13 16:46:47.276  INFO 26 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8085 (http)

过程文件:

web: java -Dserver.port=8085 -jar target/app.war

感谢任何帮助

编辑:

@jusermar10 感谢您的回复。是的,我正在尝试设置静态端口,并且不想使用@user3314492 指出的由heroku 分配的端口。我知道动态端口方法工作正常。我们面临的问题是我们正在尝试使用 nginx 代理进行缓存,使用 https://github.com/theoephraim/nginx-buildpack 的 builpack。如果我们使用动态端口,nginx 配置文件也会使用它,这就是它抛出以下错误的原因

2018-04-14T17:09:24.427513Z app[web.1]: buildpack=nginx at=nginx-start
2018-04-14T17:09:24.440105Z app[web.1]: nginx: [emerg] bind() to 0.0.0.0:10949 failed (98: Address already in use)
2018-04-14T17:09:24.440137Z app[web.1]: 2018/04/14 17:09:24 [emerg] 159#0: bind() to 0.0.0.0:10949 failed (98: Address already in use)
2018-04-14T17:09:24.940239Z app[web.1]: nginx: [emerg] bind() to 0.0.0.0:10949 failed (98: Address already in use)
2018-04-14T17:09:24.940285Z app[web.1]: 2018/04/14 17:09:24 [emerg] 159#0: bind() to 0.0.0.0:10949 failed (98: Address already in use)
2018-04-14T17:09:25.440529Z app[web.1]: nginx: [emerg] bind() to 0.0.0.0:10949 failed (98: Address already in use)
2018-04-14T17:09:25.440569Z app[web.1]: 2018/04/14 17:09:24 [emerg] 159#0: bind() to 0.0.0.0:10949 failed (98: Address already in use)
2018-04-14T17:09:25.940679Z app[web.1]: nginx: [emerg] bind() to 0.0.0.0:10949 failed (98: Address already in use)
2018-04-14T17:09:25.940746Z app[web.1]: 2018/04/14 17:09:24 [emerg] 159#0: bind() to 0.0.0.0:10949 failed (98: Address already in use)
2018-04-14T17:09:26.440833Z app[web.1]: nginx: [emerg] bind() to 0.0.0.0:10949 failed (98: Address already in use)
2018-04-14T17:09:26.440876Z app[web.1]: 2018/04/14 17:09:24 [emerg] 159#0: bind() to 0.0.0.0:10949 failed (98: Address already in use)
2018-04-14T17:09:26.940976Z app[web.1]: nginx: [emerg] still could not bind()
2018-04-14T17:09:26.941031Z app[web.1]: 2018/04/14 17:09:24 [emerg] 159#0: still could not bind()
2018-04-14T17:09:26.941552Z app[web.1]: buildpack=nginx at=exit process=nginx
2018-04-14T17:09:26.946943Z system[web.1]: Process exited (exit status 1)
2018-04-14T17:09:26.965949+00:00 system[web.1]: State changed from up to crashed

【问题讨论】:

    标签: tomcat spring-boot heroku


    【解决方案1】:

    请在Procfile 中将服务器端口更改为--server.port=$PORT。 Heroku 会为你动态分配端口。

    【讨论】:

    • 我认为问题更多是关于如何使它在静态端口上而不是在 Heroku 生成的动态端口上工作。我也有兴趣知道如何使用静态端口使其工作。
    • 我相信在heroku中定义静态端口是不可能的。它总是动态分配端口。不幸的是,我找不到任何关于此的 heroku 开发中心文章。
    • @jusermar10 我更新了这个问题。请看看你是否可以帮助我。
    • @raghav 对迟到的回复表示歉意。我刚刚查看了 nginx 构建包配置 nginx.conf.erb 文件 (listen <%= ENV["PORT"] %>;) 。它正在从环境PORT 变量监听端口。你试过改变吗?
    • @jusermar10 感谢您的回复。我按照dasherydev.wordpress.com/2016/02/27/… 弄清楚了。一会儿我会公布答案
    【解决方案2】:

    你可以这样设置端口,它会工作-Dserver.port=${PORT:8085}

    【讨论】:

      猜你喜欢
      • 2017-04-04
      • 2019-08-03
      • 2020-06-27
      • 2020-02-28
      • 2016-09-30
      • 2021-07-25
      • 1970-01-01
      • 2020-10-16
      • 1970-01-01
      相关资源
      最近更新 更多