{"id":28698,"date":"2024-01-24T12:30:00","date_gmt":"2024-01-24T18:30:00","guid":{"rendered":"https:\/\/www.rosehosting.com\/blog\/?p=28698"},"modified":"2023-12-28T04:59:28","modified_gmt":"2023-12-28T10:59:28","slug":"how-to-fix-err_connection_refused","status":"publish","type":"post","link":"https:\/\/www.rosehosting.com\/blog\/how-to-fix-err_connection_refused\/","title":{"rendered":"How to Fix ERR_CONNECTION_REFUSED"},"content":{"rendered":"
<\/p>\n\n\n\n
In this tutorial, we will show you how to fix the ERR_CONNECTION_REFUSED error that can happen both when accessing other websites as well as when trying to access your own website. This error shows up when trying to access a webpage and your connection to it gets refused by the server. However, this error can sometimes occur even though the server is not refusing your connection.<\/p>\n\n\n\n\n\n\n\n
If this error occurs only when accessing your own webpage hosted on a Linux VPS, then the web server or the firewall on your server is refusing the connections initiated by your browser. You will need to check whether ports 80 or 443 are open on your VPS. You can do this in different ways depending on which firewall software you are using.<\/p>\n\n\n\n
Using This is what the output should be:<\/p>\n\n\n\n Port 80 needs to be open for regular HTTP connections, while port 443 is for secure HTTP connections (HTTPS). If it isn’t open, then you can use the following commands to add them:<\/p>\n\n\n\n Once you do that, you can reload If you are using If you see these ports in the output of the command together with the ACCEPT term, then you do not need to change anything as your server is already allowing connections on that port. Otherwise, if the rules are set to DROP connections from these ports, you can change that with these two commands:<\/p>\n\n\n\n If necessary, run these as a superuser (by using sudo) in order to execute them. Then, once done, you can save your iptables configuration with the following command:<\/p>\n\n\n\n Now, make sure that your web server is running. The command for this will depend on which Linux distribution you are running, as well as depending on which webserver software you are using.<\/p>\n\n\n\n RHEL-based Distributions (Such as AlmaLinux):<\/p>\n\n\n\n Debian-based Distributions (Such as Ubuntu):<\/p>\n\n\n\n If your server is stopped, start it by replacing the word ‘status’ with ‘start’ in the command corresponding with the webserver you are using.firewall-cmd<\/code> we can easily check which ports are currently open by using this command:<\/p>\n\n\n\n
firewall-cmd --list-ports<\/pre>\n\n\n\n
80\/tcp\n443\/tcp<\/pre>\n\n\n\n
firewall-cmd --permanent --add-port=80\/tcp\nfirewall-cmd --permanent --add-port=443\/tcp<\/pre>\n\n\n\n
Firewalld<\/code> to apply the changes:<\/p>\n\n\n\n
firewall-cmd --reload\nsuccess<\/pre>\n\n\n\n
iptables<\/code> as your firewall of choice, then the commands are slightly different. You can check which ports are open by using the following command:<\/p>\n\n\n\n
iptables -L -n | grep 80\niptables -L -n | grep 443<\/pre>\n\n\n\n
iptables -I INPUT 1 -p tcp -m multiport --dports 80,443 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT\niptables -I INPUT 1 -p tcp -m multiport --dports 80,443 -m conntrack --ctstate ESTABLISHED -j ACCEPT<\/pre>\n\n\n\n
iptables-save > \/etc\/iptables.backup<\/pre>\n\n\n\n
systemctl status httpd.service\nsystemctl status nginx.service<\/pre>\n\n\n\n
sudo systemctl status apache2.service\nsudo systemctl status nginx.service<\/pre>\n\n\n\n
Now, try to open your webpage again and see if the issue is resolved. Now that the ports are open and the webserver is running using those ports, you should be able to access your webpage without any issues.<\/p>\n\n\n\n