httpd部署问题:本地可访问网页但其他电脑无法访问
Hey there! Let's break down why other machines can't reach your Apache setup, even though you can access it locally. Here are the key checks to run through:
1. Confirm the IP Address You're Using
First off, 172.31.30.53 looks like a private internal IP address (common in AWS EC2 or local network setups).
- If the remote computers are not on the same local network/VPC, you'll need to use your server's public IP instead. Run
curl ifconfig.meon your server to grab its public IP, then test that address from the remote machine. - If they are on the same network, start with basic connectivity: run
ping 172.31.30.53from the remote computer. If ping fails, there's a network routing issue to fix before diving into Apache settings.
2. Check if Port 80 is Reachable Externally
Your local nmap scan shows port 80 is open, but we need to confirm it's accessible from outside the server:
- On the remote machine, run this command:
If the result saysnmap 172.31.30.53 -p 80filteredorclosed, traffic to port 80 is being blocked somewhere.
3. Double-Check Firewall Rules (Beyond UFW)
Even though UFW allows port 80, there might be other firewalls in play:
- If you're using a cloud server (like AWS EC2): Verify your security group allows inbound traffic on port 80 from the remote machine's IP (or
0.0.0.0/0for temporary testing). - If you're on RHEL/CentOS (since you're using
httpdinstead ofapache2): Check iffirewalldis running and permitting HTTP traffic:
Ifsudo firewall-cmd --list-allhttpisn't listed in theservicessection, add it with:sudo firewall-cmd --add-service=http --permanent sudo firewall-cmd --reload
4. Update Apache Configuration for Modern Versions
Your <Directory> block uses Apache 2.2-style authorization rules (Order allow,deny / allow from all). If you're running Apache 2.4 (standard on most modern systems), switch to the newer syntax to avoid compatibility issues:
Edit your /etc/httpd/conf/httpd.conf file and update the directory block:
<Directory /var/www/html> AllowOverride None # Replace old authorization rules with this line Require all granted </Directory>
Then restart Apache to apply changes:
sudo apachectl restart
5. Verify Apache is Listening on All Interfaces
Your config has Listen 0.0.0.0:80 (which tells Apache to listen on all network interfaces), but let's confirm this is working:
sudo netstat -tulpn | grep httpd
You should see a line like tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN [PID]/httpd — this confirms Apache isn't restricted to localhost only.
Start with these checks, and share what you find so we can narrow it down further!
内容的提问来源于stack exchange,提问作者Heejun Choi

