azurenext.jsazure-devopsazure-web-app-service

Web App Azure nextjs didn't respond to HTTP pings on port: 8080


I am migrating from Vercel to Azure Web App. I've set up GitHub action for CI/CD. The build and deploy jobs below are successful. However, I get an error didn't respond to HTTP pings on port: 8080, failing site start in Azure logs.

I thought the issue is that Next.js is 3000 so I've added WEBSITES_PORT 3000 to Azure settins environment variables, but I still get didn't respond to HTTP pings on port: 3000, failing site start.

I also try this solution but not working.

Azure logs:

2025-02-21T23:36:06.839Z INFO  - Stopping site appname because it failed during startup.
2025-02-21T23:47:17.229Z INFO  - Starting container for site
2025-02-21T23:47:17.237Z INFO  - docker run -d --expose=8080 --name appname_1_86d342a9 -e WEBSITE_USE_DIAGNOSTIC_SERVER=true -e WEBSITES_PORT=8080 -e WEBSITE_SITE_NAME=appname -e WEBSITE_AUTH_ENABLED=False -e PORT=8080 -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=appname-eeg0cha0cfh3d43b9.uksouth-01.azurewebsites.net -e WEBSITE_INSTANCE_ID=2a8f5b2341b72347f9c6e13dac66a7d1428460c1a4c8a1b3534f1beafa4249f1 -e HTTP_LOGGING_ENABLED=1 appsvc/node:20-lts_20250213.3.tuxprod
2025-02-21T23:47:24.355Z INFO  - Initiating warmup request to container appname_1_86d342a9 for site appname
2025-02-21T23:47:41.757Z INFO  - Waiting for response to warmup request for container appname_1_86d342a9. Elapsed time = 17.3826041 sec
2025-02-21T23:47:51.526Z ERROR - Container appname_1_86d342a9 for site appname has exited, failing site start
2025-02-21T23:47:51.553Z ERROR - Container appname_1_86d342a9 didn't respond to HTTP pings on port: 8080, failing site start. See container logs for debugging.

Note that I am not using Docker in my repo so docker run -d --expose=8080 comes from Azure.

This is yml GitHub workflow generated automatically by Azure:

name: Build and deploy Node.js app to Azure Web App

on:
  push:
    branches:
      - master
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@v4

      - name: Set up Node.js version
        uses: actions/setup-node@v3
        with:
          node-version: '20.x'
          cache: 'npm'

      - name: npm install, build, and test
        run: |
          npm ci          
          npm run build --if-present
          npm run test --if-present
          npm prune --production 

      - name: Zip artifact for deployment
        run: |
          # Adjust paths to include only necessary files (e.g., package.json, build output, node_modules)
          zip -r release.zip package*.json dist/ node_modules/ -i '*.js' '*.json' '*.html' '*.css' # Example, customize based on your project

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v4
        with:
          name: node-app
          path: release.zip

  deploy:
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: 'Production'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v4
        with:
          name: node-app

      - name: 'Deploy to Azure Web App'
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v3
        with:
          app-name: 'app-name'
          slot-name: 'Production'
          package: release.zip
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE }}

Solution

I've added that "start": "node_modules/next/dist/bin/next start" to package.json and removed the Zip file from the build job as per below, so using standalone instead of zip.

Now it builds and deploys in just 3 min, whereas before was like 35 min or I guess because of the zip file. Probably it was a timeout error, but I am a hobbyist so I am not sure.

- name: Copy static files
        run: |
          cp -R ./.next/static ./.next/standalone/.next/static

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v4
        with:
          name: node-app
          path: .next/standalone
          include-hidden-files: true

And so changed package: . in the build job to deploy the standalone folder instead of the zip.


Solution

  • I've added "start": "node_modules/next/dist/bin/next start" to package.json and removed the Zip file from the build job as per below, so using standalone instead of zip, hence changed to package: ..

    Now it builds and deploys in just 3 min, whereas before was like 35 min or I guess because of the zip file. Probably it was a timeout error, but I am a hobbyist so I am not sure.

    - name: Copy static files
            run: |
              cp -R ./.next/static ./.next/standalone/.next/static
    
          - name: Upload artifact for deployment job
            uses: actions/upload-artifact@v4
            with:
              name: node-app
              path: .next/standalone
              include-hidden-files: true