Search code examples
linuxazureazure-virtual-machine

I hosted my website on Azure Linux VM but I can’t access the website with the designated ip on chrome it doesn’t not respond


I'm hosting my website on an Azure Linux VM, but I can't access it using the ip given. I have tried adding inbound rules, but there was no result. I also tried allowing the VM to listen to the particular ports 80 and 83 and added an inbound rule - no result still. I tried redeploying, but no changes. I tried reapplying, but still no results. I still can't access it through the IP on Chrome.

I am still new to azure VMs as I am only used to aws ec2. I don't know what else to do to resolve this. Most of the solutions I see here are for window VMs.


Solution

  • To resolve the issue, Check the firewall settings on the VM itself it allows inbound traffic on the ports on your website.

    Added NSG port like below:

    enter image description here

    Check the status of the web server (Apache or Nginx) running on the VM and make sure that it is listening on the correct ports.

    sudo ufw status
    sudo ufw allow 80
    sudo ufw allow 443
    
    sudo systemctl status apache2
    or
    sudo systemctl status nginx
    
    sudo systemctl status apache2
    ● apache2.service - The Apache HTTP Server
         Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
         Active: active (running) since Thu 2023-12-28 05:50:49 UTC; 31min ago
           Docs: https://httpd.apache.org/docs/2.4/
       Main PID: 3756 (apache2)
          Tasks: 55 (limit: 4080)
         Memory: 10.5M
         CGroup: /system.slice/apache2.service
                 ├─3756 /usr/sbin/apache2 -k start
                 ├─3759 /usr/sbin/apache2 -k start
                 └─3760 /usr/sbin/apache2 -k start
    
    Dec 28 05:50:48 vm1linux1 systemd[1]: Starting The Apache HTTP Server...
    Dec 28 05:50:49 vm1linux1 systemd[1]: Started The Apache HTTP Server.
    

    enter image description here

    Still if the web server is not running, start it by running below command:

    sudo systemctl start apache2
    or
    sudo systemctl start nginx
    

    Now I am hosting my website on an Azure Linux VM check the below:

    sudo apt update
    sudo apt upgrade
    sudo apt install -y apache2
    

    Output:

    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following additional packages will be installed:
      apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libjansson4
      liblua5.2-0 ssl-cert
    Suggested packages:
      apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser openssl-blacklist
    The following NEW packages will be installed:
      apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap
      libjansson4 liblua5.2-0 ssl-cert
    0 upgraded, 11 newly installed, 0 to remove and 0 not upgraded.
    Need to get 1872 kB of archives
    ...................................
    ..................................
    

    enter image description here

    Now you can create new file:

    cd /var/www/html
    ls
    vi index.html
    sudo vi test.html
    

    In file you can add your own sudo vi test.html , for sample I added below html code.

    <html>
        
        <h1> This is my website</h1>
    
    </html>
    

    change the name file:

    #To save and change the file use below:
    sudo mv index.html back.html
    sudo mv test.html back.html
    

    enter image description here

    enter image description here