Ubuntu 18.04下用LAMPP自建网站后公网IP无法访问求助
Hey there! Let’s walk through the common issues that might be blocking your public IP access, even after setting up port forwarding on your router. Let’s start with the basics and work our way out:
1. Verify LAMPP/Apache is Running Correctly
First, make sure your Apache server is up and listening on the right network interface.
- Check service status with:
Look for "Apache" marked as running.sudo /opt/lampp/lampp status - Confirm it’s listening on all interfaces (not just localhost):
You should see output likess -tulpn | grep httpdLISTEN 0 1024 0.0.0.0:80 0.0.0.0:*or:::80—if it only shows127.0.0.1:80, edit/opt/lampp/etc/httpd.conf, find theListen 80line, and ensure it’s not bound to localhost. Restart Apache withsudo /opt/lampp/lampp restart apacheafter changes.
2. Check Ubuntu’s Local Firewall (UFW)
Ubuntu 18.04 uses UFW by default, which might be blocking incoming traffic to your web ports.
- Check current rules:
sudo ufw status - If port 80 (HTTP) or 443 (HTTPS) isn’t allowed, add them:
sudo ufw allow 80/tcp sudo ufw allow 443/tcp sudo ufw reload
3. Double-Check Router Port Forwarding Settings
Even if you set up a virtual server, small misconfigurations can break access:
- Confirm the internal IP matches your Ubuntu machine’s local IP (find it with
ip a—look for theinetaddress under your active network adapter likeeth0orwlan0). - Ensure the external and internal ports match (e.g., external 80 → internal 80; if you changed Apache’s port, update both to match).
- Make sure the protocol is set to TCP (HTTP/HTTPS uses TCP; avoid UDP-only unless you need it).
- Restart your router—some devices require a reboot to apply port forwarding changes.
4. Test for ISP Port Blocking
Many residential ISPs block common web ports (80, 443) to prevent home hosting. Try a workaround:
- Edit
/opt/lampp/etc/httpd.conf, changeListen 80toListen 8080, then restart Apache. - Update your router’s port forwarding to map external port 8080 to internal port 8080.
- Try accessing your site via
http://[your-public-ip]:8080—if this works, your ISP is likely blocking port 80. You can either use a non-standard port or contact your ISP to request unblocking.
5. Confirm You Have a Public (Non-CGNAT) IP
Some ISPs use Carrier-Grade NAT (CGNAT), which means your "public IP" is shared with other users, and port forwarding won’t work.
- Check your public IP with
curl ifconfig.me(or search "what’s my IP" in a browser). - Ask a friend outside your network to run
telnet [your-public-ip] 80—if the connection fails and all other steps check out, you might be on CGNAT. Contact your ISP to get a dedicated public IP, or use an internal tunneling service.
6. Test Local Network Access First
Rule out local issues by accessing your site using your Ubuntu machine’s local IP (e.g., http://192.168.1.100). If this fails:
- Check Apache’s error logs at
/opt/lampp/logs/error_logfor clues about configuration issues. - Ensure your virtual host config (if you’re using one) allows external access—look for
Require all grantedin the<Directory>block (Apache 2.4+ syntax).
内容的提问来源于stack exchange,提问作者swagato chakraborty

