Azure Web App Failing

Shubhankar Khandai 60 Reputation points
2024-11-24T19:20:56.86+00:00

I have been trying to deploy my Flask APIs(standalone APIs without any frontend) on Azure Web App using GitHub actions.

While I have been trying to deploy, though the deployment is successful, but however my application isnt running and I am getting error on the Log Stream for the particular Web App.

My APIs have been deployed on PORT 443

if __name__ =="__main__":
    application.run(debug=True,host="0.0.0.0", port=443)

And I have also tested it on localhost and have got the response.

But upon deployment below are the log

User's image
I have also added and Environment Variable for WEBSITES_PORT = 443.

Not understanding that while my application is deployed on 443 then why the web app is pinging on 8000

Please help and let me know if I am doing anything wrong

Azure Private Link
Azure Private Link
An Azure service that provides private connectivity from a virtual network to Azure platform as a service, customer-owned, or Microsoft partner services.
526 questions
Azure Web Application Firewall
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
1,021 questions
{count} votes

Accepted answer
  1. Shree Hima Bindu Maganti 1,585 Reputation points Microsoft Vendor
    2024-11-26T04:46:36.1966667+00:00

    Hi Shubhankar Khandai,
    Welcome to the Microsoft Q&A Platform!
    It seems that the issue is related to Azure's default behavior for containerized applications. By default, Azure Web App containers ping the application on port 8000.
    Check Azure Port Configuration Azure Web App expects the application to run on the port defined by the environment variable PORT. Even though you set WEBSITES_PORT=443, the default behavior requires you to use PORT instead.

    Update your Flask application to dynamically use the PORT environment variable

    import os
    if __name__ == "__main__":
        port = int(os.environ.get("PORT", 443))  # Fallback to 443 if PORT is not set
        application.run(debug=True, host="0.0.0.0", port=port)
    
    1. Set the PORT Environment Variable in Azure In the Azure Web App settings
    2. Go to Configuration > Application Settings.
    3. Add a new key PORT with the value 443.
    4. Adjust Your Deployment Configuration If you are using a Docker container:
    5. Ensure the Dockerfile or the startup command maps the correct port.
    EXPOSE 443
    CMD ["gunicorn", "-b", "0.0.0.0:443", "app:application"]
    

    If not using Docker:

    1. Ensure your GitHub Actions workflow or deployment script is not overriding the port.
    2. Verify Logs After redeploying.
    3. Check the logs in Azure's Log Stream to confirm the application is listening on the correct port.
    4. Ensure no errors indicate a mismatch in the expected and actual ports.
    5. Network Considerations for HTTPS (Port 443) If you're using port 443, remember that HTTPS traffic is typically terminated by Azure's built-in SSL endpoint, and the traffic is forwarded to your app on the PORT environment variable. Ensure no SSL configuration conflicts exist.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it.

    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.