Hosting an Application

Blogs

Exploring Google Cloud Pub/Sub: Publish/Subscribe Messaging Explained
December 31, 2024
Understanding SQL Server Linked Servers
December 31, 2024

Hosting an Application

In today’s world deploying applications on virtual machines(vms) can be scalable and cost-effective. This document explains the step-by-step process of hosting a application on windows based virtual machine. In this documentation we have taken flask application for hosting because it is a lightweight python web framework.

This guide focuses on setting up applications on windows vm, including network configurations, security, and deployment procedures. It ensures the application is accessible to the external users.

Purpose

The purpose of this document is to:

  1. The application is scaled automatically based on demand. With azure users can quickly add more resources like memory or storage therefore we can handle application fluctuations in traffic without manual intervention
  2. Azure vms provide full administrative controls over configuration of the operating systems , install software and add additional services
  3. Each vm is isolated from others which helps the applications data and processes are secure and private
  4. The hosted application can be accessed to anyone in any part of world and with azures global network of data centers, windows vms can be deployed closer to end-users which reduces latency and improving performance of applications

Scope

  1. The application can be hosted on physical servers, virtual machines, cloud services or other platforms each provides different levels of flexibility, control and scalability. The hosting platform should be chosen based on the application’s specific requirements.
  2. This documentation shows hosting on vm
  3. Hosting involves configuration of the network environment to ensure there is proper communication between applications, databases and users
  4. As we are hosting a small application, we are not very concerned about the volume of data but if the volume of data is large choose a suitable database management to the specific type of data
  5. Hosting an application on another platform may cost significantly high this type of hosting is costless and very budget friendly for small applications

Step 1: Get Network Configuration Details

  1. Open PowerShell as Administrator in the VM.
  2. Run the following command: bash

ipconfig

  1. You will get the following details: yaml

Connection-specific DNS Suffix  . :

Link-local IPv6 Address . . . . . : xxxxxxxx

IPv4 Address. . . . . . . . . . . : xx.x.x.x

Subnet Mask . . . . . . . . . . . : xxx.xxx.xxx.x

Default Gateway . . . . . . . . . : xx.x.x.x

Step 2: Modify Flask Application Settings

  1. Open your Flask application.
  2. Locate the line app.run(debug=True) and replace it with: python

app.run(host=’0.0.0.0′, port=5000)

The 5000 port is assigned for Flask. If your application uses a different port, replace 5000 with the correct port number.

Step 3: Configure Windows Firewall for Inbound and Outbound Traffic

  1. Inbound Configuration:
    • Open Control Panel in the VM.
    • Navigate to System and Security > Windows Defender Firewall.
    • In the Windows Defender Firewall, click on Inbound Rules in the Actions column.
    • Click New Rule and a popup will appear.
    • Select Port, choose TCP, and enter the port number (e.g., 5000).
    • Select Allow the connection.
    • Choose when the rule applies (Domain, Private, Public).
    • Give the rule a name (e.g., AllowInboundFlaskApp).
    • Click Finish.
  2. Outbound Configuration:
    • Open Control Panel in the VM.
    • Navigate to System and Security > Windows Defender Firewall.
    • In the Windows Defender Firewall, click on Outbound Rules in the Actions column.
    • Click New Rule and a popup will appear.
    • Select Port, choose TCP, and enter the port number (e.g., 5000).
    • Select Allow the connection.
    • Choose when the rule applies (Domain, Private, Public).
    • Give the rule a name (e.g., AllowOutboundFlaskApp).
    • Click Finish.

Step 4: Configure Azure Network Security Group (NSG) Settings

  1. Log in to Azure Portal:
    • Navigate to Virtual Machines and select your Windows VM.
    • Under the Networking section, click on Network Interface.
    • Under the Network Security Group (NSG) section, click on the associated NSG.
  2. Outbound Rules:
    • In the NSG panel, click on Outbound security rules.
    • If you need to create or modify a specific rule:
      • Click Add outbound rule.
      • Set Source to Any (or specify IPs if needed).
      • Set Source port range to *.
      • Set Destination to Any (or restrict to specific IPs if required).
      • Set Destination port range to *.
      • Set Protocol to TCP.
      • Set Action to Allow.
      • Set a Priority value (e.g., 1000).
      • Give it a meaningful name (e.g., AllowOutboundTraffic).
      • Click Add to apply the rule.
  3. Inbound Rules:
    • In the NSG panel, click on Inbound security rules.
    • If you need to create or modify a specific rule:
      • Click Add inbound rule.
      • Set Source to Any (or specify IPs if needed).
      • Set Source port range to *.
      • Set Destination to Any (or restrict to specific IPs if required).
      • Set Destination port range to *.
      • Set Protocol to TCP.
      • Set Action to Allow.
      • Set a Priority value (e.g., 1000).
      • Give it a meaningful name (e.g., AllowInboundTraffic).
      • Click Add to apply the rule.

Step 5: Test the Application

After completing the above steps, you can test if the application is running.

  1. Open any device and enter the following URL in the browser:

Code

http://<Your_VM_Public_IP>:<port_number>

    • Replace <Your_VM_Public_IP> with the actual public IP address of your VM.
    • Replace <port_number> with the port number used by your Flask application (e.g., 5000).

This should allow you to access and test your application remotely.

CONCLUSION

By following this step-by-step guide, we have successfully hosted a Flask application on a Windows-based virtual machine in Microsoft Azure. The process ensures our application is accessible to external users while maintaining robust security and scalability.


Pramodh P

Leave a Reply

Your email address will not be published. Required fields are marked *