You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Heroku容器部署Web应用返回"Not authoritative"错误求助

Troubleshooting Heroku Docker App Returning 400/421 Errors

Let's break down what's happening here and fix this issue step by step. The biggest red flag jumps out from your logs:

2021-06-15T17:11:39.852345+00:00 app[web.1]: [main] INFO de.clique.westwood.example.html5.landingpage.buddah.App - Server started on port 54225

Heroku dynamically assigns a port to your app via the PORT environment variable—your app is hardcoding port 54225 instead of using this variable, which is the root cause of the 400/421 errors. Heroku's router can't route traffic to your app because it's listening on the wrong port.

Step 1: Update your app to listen on the Heroku-assigned PORT

Since your log shows a Java-based application, modify your code to read the PORT environment variable (with a fallback for local testing):

String port = System.getenv("PORT");
// Use 8080 as a default for local development
if (port == null || port.trim().isEmpty()) {
    port = "8080";
}
int serverPort = Integer.parseInt(port);
// Start your server using serverPort instead of the hardcoded 54225

Step 2: Fix your Docker configuration

Ensure your Dockerfile passes the PORT variable correctly to your app:

  • Update your CMD or ENTRYPOINT to use the PORT variable when starting the app. For example:
    CMD ./app --port $PORT
    
    Adjust the command to match how your app accepts port arguments—check your app's startup documentation if you're unsure.
  • You can remove any fixed EXPOSE line (Heroku ignores it), but if you want to keep it for clarity, use EXPOSE $PORT.

Step 3: Check for Host header restrictions

The "Not authoritative" message and 400 error can also occur if your app rejects requests with Heroku's domain host header (html5-landingpage-buddah.herokuapp.com). Verify your app doesn't restrict incoming requests to specific hostnames—either allow all valid Host headers or add Heroku's domain to your allowed list.

Step 4: Test locally with Heroku's environment

To confirm the fix works before deploying, run your app with the PORT variable set:

PORT=5000 ./app

Visit http://localhost:5000—if it loads correctly, deploy the updated code/Docker image to Heroku.

After redeploying, check your logs again—you should see your server start on the port provided by Heroku (e.g., Server started on port 34567 instead of 54225). The router will now route traffic correctly, and the 400/421 errors should disappear.

内容的提问来源于stack exchange,提问作者Oliver

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 10:57:28