Heroku容器部署Web应用返回"Not authoritative"错误求助
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
CMDorENTRYPOINTto use thePORTvariable when starting the app. For example:
Adjust the command to match how your app accepts port arguments—check your app's startup documentation if you're unsure.CMD ./app --port $PORT - You can remove any fixed
EXPOSEline (Heroku ignores it), but if you want to keep it for clarity, useEXPOSE $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

