Azure App Service unable to set a port for Django Project which is deployed using GitHub Actions.

Amogh Joshi 20 Reputation points
2023-05-25T19:12:27.5+00:00

I am learning Azure and have deployed a Web Application (Azure Quickstart Templates) - https://github.com/Azure-Samples/msdocs-python-django-webapp-quickstartonto Azure App Service using GitHub Action and using Docker Container. Want to use a port for hosting other then 443 which is default one. Have created a startup.txt file within repository for binding the port using gunicorn but it is not able to do so. Deployment logs show no errors.

User's image

Also tried to set it up using startup command option on the Azure Portal but still same issue.

User's image

Windows for business | Windows Client for IT Pros | Devices and deployment | Set up, install, or upgrade
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,961 questions
0 comments No comments
{count} votes

Accepted answer
  1. Konstantinos Passadis 19,591 Reputation points MVP
    2023-05-27T10:50:04.8933333+00:00

    Hello @Amogh Joshi !

    Well i dont have good news

    Using Azure Web apps , all the traffic is controlled by Azure and it is only on 80 and 443

    We can change the inside port and add the WEBSITES_PORT , but it is only between the WEB APP and the Django or whatever App

    to make this happen , only with Containers App , or other services

    Unlike Cloud Services (web/worker roles) and Virtual Machines, Web Apps don't have a port-mapping feature. That is... the only ports open for Web Apps are 80 and 443.

    Traffic Manager does not provide port-mapping. You'd need to run your own proxy for handling this.

    https://serverfault.com/questions/751504/azure-web-app-port-mapping-forwarding/751548#751548

    So dont waste any time on this , but try to work with other means !

    I hope this helps!

    Kindly mark the answer as Accepted and Upvote in case it helped!

    Regards

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Konstantinos Passadis 19,591 Reputation points MVP
    2023-05-25T19:17:04.1766667+00:00

    Hello @Amogh Joshi !

    Welcome to Microsoft QnA!

    As we read from https://learn.microsoft.com/en-us/azure/app-service/configure-custom-container?pivots=container-linux&tabs=debian

    Configure port number

    By default, App Service assumes your custom container is listening on port 80. If your container listens to a different port, set the WEBSITES_PORT app setting in your App Service app. You can set it via the Cloud Shell. In Bash:

    Azure CLI

    az webapp config appsettings set --resource-group <group-name> --name <app-name> --settings WEBSITES_PORT=8000
    

    In PowerShell:

    Azure PowerShell

    Set-AzWebApp -ResourceGroupName <group-name> -Name <app-name> -AppSettings @{"WEBSITES_PORT"="8000"}
    

    When deploying applications on Azure App Service, port binding is handled by Azure automatically. Azure App Service expects your application to listen on port 80 for HTTP requests or 443 for HTTPS, and it maps the incoming requests to that port inside the container.

    However, if you need to use a different port, you should be able to specify it in the Dockerfile or the application settings in Azure portal and use it with the WEBSITES_PORT app setting.

    Update the Dockerfile. If you're using something like EXPOSE 8080, you would change this line to the port you wish to use, e.g., EXPOSE 8000.

    Update the Azure app setting. Navigate to the Azure portal, go to your App Service, and then go to Configuration > Application settings. Add a new setting with the name WEBSITES_PORT and the value being the port you wish to use, e.g., 8000.

    It's important to note that this won't change the port that clients use to access your application, which will still be 80/443, but it will change the port that your application listens on within its container. This might be required if you're using a custom image that expects to listen on a specific port.

    Regarding your startup.txt file, since you're using Docker, the application startup command should be defined in the Dockerfile CMD or ENTRYPOINT instruction rather than a startup.txt file. The startup.txt file is usually used when deploying code directly without a Docker container.

    You also mentioned you're using gunicorn, you can specify the port using something like this in your Dockerfile:

    dockerfile
    
    CMD ["gunicorn", "-b", ":8000", "myapp:app"]
    

    Remember to replace myapp:app with the actual WSGI application you're trying to run.

    I hope this helps!

    Kindly mark the answer as Accepted and Upvote in case it helped!

    Regards


  2. Amogh Joshi 20 Reputation points
    2023-05-26T08:24:04.5+00:00

    Still the same issue.

    User's image

    User's image


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.