Invalid Host Header

Wael Kodmani 20 Reputation points
2024-06-13T11:16:36.0166667+00:00

Hello All,

I'm trying to run a node js container, using a docker image in ACR. The docker image is running well locally, but when trying to run on Azure App Service "Web App" it's showing me "Invalid Host Header".

I'm trying to browse the app by https://app-name.azurewebsites.net, replacing the app name with the name of my app.

Does anyone know a solution to this problem?

some info:

Node JS Application "built by npm/webpack --cli".

Docker is exposed in port 3000.

Set WEBSITE_PORT TO 3000.

Gave a high number if WEBSITE_CONTAINER_START_TIME_LIMIT.

Enable public access to the web app.

Trying access by virtual IP that Azure provided.

I stopped and started the container multiple times.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,903 questions
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
966 questions
{count} votes

Accepted answer
  1. ajkuma 26,636 Reputation points Microsoft Employee
    2024-06-17T19:05:41.8966667+00:00

    @Wael Kodmani edited Serverdev in webpack files like the following command:

    Update:

     devServer: {
        allowedHosts: '<azure-name-app>.azurewebsites.net',
    }
    

    --

    Apologies for the delayed response.

    If you haven't done, you may modify the code in the code about listening.

    const express = require('express')
    
    const app = express()
    
    const port = process.env.PORT || 3000
    
     
    
    app.get('/', (req, res) => {
    
      res.send('Hello World!')
    
    })
    
     
    
    app.listen(port, () => {
    
      console.log(`Example app listening at http://localhost:${port}`)
    
    

    There is discussion on similar SO thread, you may take a look the approaches outlined

    Based on my understanding of your issue, depending on your web framework.

    Just to highlight , listen binds to the local host, localhost, interface by default (127.0.0.1 or ::1, depending on the operating system configuration). If you are running Fastify ( as an example) in a container, you may need to bind to 0.0.0.0. Be careful when deciding to listen on all interfaces; it comes with inherent security risks. See the documentation for more information.

    Inside Docker, you should mention explicitly '0.0.0.0'. By default fastify is listening only the localhost 127.0.0.1 interface. To listen on all available IPv4 interfaces you should be modified to listen on 0.0.0.0 like so I change it to the following

     

    Once Oryx will also execute npm run build, you can take advantage and set up PM2 to serve the build folder with pm2 serve /home/site/wwwroot/build --no-daemon
    see the article section Custom Startup Commands

    Ref:  

    Configure a Node.js app for Azure App Service

    Kindly let us know, I'll follow-up with you further.


    If my answer helped (pointed, you in the right direction) > please click Accept Answer - it will benefit the community/users to find the answer quickly.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.