Problem Accessing Ports 443 and 80 on an Ubuntu VM

Connor Wynne 1 Reputation point
2021-11-16T00:14:56.413+00:00

Ports 80 and 443 can not be accessed in the VM. NSG is set to allow traffic inbound on both and the ufw is disabled. Network outside of the VM is allowing traffic on both 80 and 443.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,044 questions
{count} votes

2 answers

Sort by: Most helpful
  1. vipullag-MSFT 26,492 Reputation points Moderator
    2021-11-17T05:43:14.28+00:00

    @Connor Wynne

    Thanks for clarifying the issue and sharing the details.

    Here are few suggestions to try and see if that helps fixing your issue.

    Run any of the below commands and check if the ports are listening or not:

    sudo lsof -i -P -n | grep LISTEN  
    sudo netstat -tulpn | grep LISTEN  
    sudo ss -tulpn | grep LISTEN  
    sudo lsof -i:80## see a specific port such as 80##  
    

    Incase the ports 80 and 443 are not listening, the reason might be there is no program listening on port 80 so it's closed and you can't connect to it (as you have stopped the Apache).
    Re-enable the services on the ports and check if the ports are listening or not.

    If the ports are not listening, then you can try adding them to internal firewall and ensure to save the firewall changes. Use below commands:

    sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT  
    sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT  
    sudo service iptables save  
    

    Ensure the apache configuration has correct port binding (Listen 80) in the below file.

    sudo vi /etc/apache2/ports.conf  
    

    Once this is done, you have added the ports to internal firewall and the services are up and running on the required ports. Please try and see the ports are open or not using this link.

    If the ports are still showing as closed, then it could be issue with the NSG.

    As you mentioned that the ports are allowed on the NSG attached to the VM, there might be other NSG's impacting the subnet in which the VM is deployed.
    On the Azure Portal check if the Network interface of the VM has only the NSG that you have created associated with it.

    Hope that helps.
    Please 'Accept as answer' if the provided information is helpful, so that it can help others in the community looking for help on similar topics.

    0 comments No comments

  2. Gene Gleyzer 0 Reputation points
    2023-06-27T21:45:21.06+00:00

    Everything worked, except the last command was:

    sudo /sbin/iptables-save
    

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.