安卓设备连接XAMPP服务器部分站点不可用,提示net::ERR_CONNECTION_REFUSED求助
Hey there, let's troubleshoot this net::ERR_CONNECTION_REFUSED issue step by step—since one site works fine, we know the core network setup is partially functional, so we can narrow down the causes quickly.
First, let's confirm your mysite is set up correctly in XAMPP:
- If you're using virtual hosts, open
httpd-vhosts.conf(usually located atxampp/apache/conf/extra/) and verify the<VirtualHost>block formysiteincludes proper access permissions for your local network. Here's a working example:<VirtualHost *:80> DocumentRoot "C:/xampp/htdocs/mysite" ServerName mysite.local <Directory "C:/xampp/htdocs/mysite"> AllowOverride All Require all granted </Directory> </VirtualHost> - If you're not using virtual hosts, ensure
mysiteis directly inside XAMPP'shtdocsfolder (e.g.,xampp/htdocs/mysite). Also, check folder permissions:- On Windows: Right-click the
mysitefolder → Properties → Security → Confirm your user account has read/write access. - On macOS/Linux: Run
sudo chmod -R 755 /opt/lampp/htdocs/mysiteto set universal read/execute permissions.
- On Windows: Right-click the
A common culprit here is Apache only listening to localhost, or firewalls blocking the connection:
- Open
httpd.conf(inxampp/apache/conf/) and check theListendirective—it should beListen 80(notListen 127.0.0.1:80), which lets Apache accept connections from any device on your local network. - Firewall checks:
- Windows: Go to Windows Defender Firewall → Allow an app through firewall → Ensure "Apache HTTP Server" is allowed for private networks.
- macOS: System Settings → Network → Firewall → Options → Confirm Apache is listed and allowed.
- Linux: Run
sudo ufw allow 80/tcpthensudo ufw reloadto open port 80.
- Also, check if another program is using port 80 (e.g., Skype, another web server). Use
netstat -ano | findstr :80(Windows) orlsof -i :80(macOS/Linux) to identify conflicts. If found, stop the conflicting program or change Apache's port inhttpd.conf(e.g.,Listen 8080) and update your URL tohttp://192.168.x.x:8080/mysite.
Before trying on Android, confirm you can access http://192.168.x.x/mysite from your computer's browser (not just http://localhost/mysite):
- If this fails, the issue is with your server setup, not the Android device.
- If
localhost/mysiteworks but the local IP URL doesn't, it's almost certainly a network/firewall or Apache listening issue.
Make sure your Android device isn't the bottleneck:
- Ensure it's connected to the same Wi-Fi network as your XAMPP computer—mobile data won't work for local server access.
- Clear your Android browser's cache/cookies, or try a different browser (Chrome, Firefox) to rule out browser-specific glitches.
- Temporarily disable any ad blockers or VPNs on Android—these can sometimes block connections to local servers.
If mysite has a .htaccess file in its root directory, it might contain rules that block external access or rewrite URLs incorrectly. Temporarily rename it to .htaccess.bak and try accessing the site again. If it works, you'll need to adjust the .htaccess rules to allow connections from your local network.
If you've tried all these steps and still run into issues, share details like your OS, XAMPP version, and whether you're using virtual hosts, and we can dig deeper.
内容的提问来源于stack exchange,提问作者Nahla Saad Aldeen

