How to Fix “Connection Refused” Error
How to Fix “Connection Refused” Error
(SSH, Nginx, MySQL, RDP)
The “Connection Refused” error is one of the most frustrating problems for developers and VPS users. It happens when your client — whether it’s SSH, a web browser, or a database tool — tries to reach a server, but the server rejects the request.
Unlike a timeout, which means the server didn’t answer at all, “connection refused” indicates that the server is reachable but not allowing the connection. This issue appears in many contexts: SSH login attempts, web services like Nginx or Apache, databases such as MySQL or PostgreSQL, or even Windows Remote Desktop (RDP).
In this guide, you’ll learn the most common causes of “connection refused” and practical solutions to fix them across different environments.
What Does “Connection Refused” Mean?
When a service refuses a connection, it usually means one of the following:
● The target service (like SSH or MySQL) is not running
● Firewall rules are blocking the port
● The wrong host or port is used in configuration
● Server resources are overloaded and cannot handle new sessions
● Access is restricted by security settings
Understanding these root causes is the first step toward fixing the problem.
Common Causes of Connection Refused
Before diving into service-specific fixes, let’s look at the universal reasons:
1. Service not running – for example, the SSH daemon (sshd) or MySQL server has stopped.
systemctl status ssh
2. Firewall rules blocking traffic – ufw, iptables, or Windows Firewall may reject the request.
sudo ufw status
3. Wrong port or host – trying to connect to a service on the wrong IP or port.
4. Server overload – if a VPS is under heavy load, new requests may be refused.
Fixing “Connection Refused” for SSH
Secure Shell (SSH) is the most frequent case for this error.
Step 1: Check if SSH is running
systemctl status ssh
sudo systemctl start ssh
If the service is inactive or failed to start, restart it and check logs in /var/log/auth.log.
Step 2: Verify firewall rules
Ensure port 22 (or your custom SSH port) is open:
sudo ufw status
Step 3: Confirm the correct port and host
If SSH is configured to use a different port in /etc/ssh/sshd_config, update your connection:
ssh -p 2222 user@server_ip
If you want a reliable environment to practice and run SSH securely, try our Linux VPS.
Fixing “Connection Refused” for Web Services (Nginx/Apache)
Web servers also return this error when ports are closed or the backend fails.
Step 1: Check service status
systemctl status nginx
systemctl restart nginx
Step 2: Validate configuration
nginx -t
Step 3: Restart backend services
If Nginx proxies requests to PHP-FPM or another application, confirm it is running.
Step 4: Open necessary ports
sudo ufw allow 80
sudo ufw allow 443
Errors like “nginx failed to connect to upstream” or “apache refused connection” often indicate a backend issue rather than the web server itself.
Fixing “Connection Refused” for Databases (MySQL/PostgreSQL)
Databases frequently cause connection issues when configured for localhost-only access.
Step 1: Ensure service is active
systemctl status mysql
sudo systemctl start mysql
Step 2: Update bind address
In /etc/mysql/my.cnf:
bind-address = 0.0.0.0
Step 3: Grant remote access permissions
GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
FLUSH PRIVILEGES;
Step 4: Allow port 3306
sudo ufw allow 3306
This resolves common issues like “mysql not accepting connections” or “postgres connection failure”.
Fixing “Connection Refused” on Windows (RDP and Services)
Remote Desktop (RDP) often shows “connection refused” if services are misconfigured.
Step 1: Confirm RDP service is running
● Open Services.msc
● Locate Remote Desktop Services
● Set to Automatic and restart
Step 2: Adjust firewall rules
Open standart port 3389 in Windows Firewall.
Step 3: Enable Remote Desktop
● Right-click This PC → Properties → Remote Desktop
● Select Allow remote connections
Need a secure setup for Remote Desktop? Explore our Windows VPS with instant RDP access.
Preventing Connection Refused Errors in the Future
You can avoid many issues with regular maintenance and monitoring:
● Monitor services with tools like htop, systemctl, or third-party dashboards.
● Configure firewall properly — allow only the ports you need.
Check logs frequently:
● Nginx (/var/log/nginx/error.log)
● SSH (/var/log/auth.log)
● MySQL (/var/log/mysql/error.log).
● Upgrade server resources if your VPS runs out of CPU, memory, or connections.
If your current server constantly runs into errors due to lack of resources, consider upgrading to a High-Performance VPS.
Conclusion
The “Connection Refused” error can appear in many forms: SSH login failures, blocked RDP sessions, Nginx upstream errors, or MySQL refusing remote access.
In most cases, the fix is straightforward: verify the service is running, check firewall rules, and confirm the correct configuration.
By applying these solutions and ensuring your VPS has the right resources, you’ll keep your projects running smoothly and minimize downtime.