You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

服务器迁移IP变更后Apache2默认主页无法加载,报404错误求助

Hey there, let's dig into this 404 issue with your Apache default page after the server migration. Since you've already checked the basics (Apache running, mod_rewrite enabled, no errors in logs), let's go through some other common culprits that might be causing this:

Troubleshooting Steps to Fix the Apache 404 Error

1. Verify the DocumentRoot Path in Apache Config

  • First, locate your Apache site configuration (usually at /etc/apache2/sites-available/000-default.conf) or main config (/etc/apache2/apache2.conf).
  • Check if the DocumentRoot directive points to a valid directory, and that the Apache user (typically www-data) has read access to it.
  • Use this command to check directory permissions:
    ls -ld /path/to/your/documentroot
    
    You should see permissions like drwxr-xr-x, and the owner/group should include www-data.

2. Ensure Default Index Files Exist & Are Recognized

  • Apache looks for files like index.html, index.php by default. Check if any of these exist in your DocumentRoot:
    ls /path/to/your/documentroot
    
  • If none exist, create a test file quickly:
    echo "<h1>Apache Test Page</h1>" > /path/to/your/documentroot/index.html
    
  • Also confirm the DirectoryIndex directive in your config includes the index file you're using. Run this to check:
    grep -n "DirectoryIndex" /etc/apache2/apache2.conf
    

3. Check Firewall & Cloud Security Group Rules

  • Even though you're getting a 404 (meaning the server is reachable), double-check that port 80 (HTTP) or 443 (HTTPS) is open on your new IP:
    • For UFW firewall: ufw status
    • If using a cloud provider (AWS, GCP, etc.), verify your security group allows incoming traffic on 80/443 to the new IP.

4. Rule Out .htaccess Interference

  • A misconfigured .htaccess file in your DocumentRoot could rewrite requests and cause a 404. Temporarily rename it to test:
    mv /path/to/your/documentroot/.htaccess /path/to/your/documentroot/.htaccess.bak
    
  • Restart Apache (sudo systemctl restart apache2) and try accessing the IP again.

5. Confirm Apache is Listening on the New IP

  • Make sure Apache isn't restricted to listening only on your old IP. Check the Listen directive:
    grep -n "Listen" /etc/apache2/apache2.conf
    
  • If it shows Listen old_ip:80, change it to Listen 80 (to listen on all IPs) or Listen new_ip:80, then restart Apache.

6. Fix File/Directory Permission Details

  • Ensure all files in DocumentRoot are readable by www-data:
    chmod -R 644 /path/to/your/documentroot/*
    
  • Set directory permissions to 755 so Apache can traverse them:
    chmod -R 755 /path/to/your/documentroot/
    
  • If needed, correct the owner/group of the directory:
    chown -R www-data:www-data /path/to/your/documentroot
    

If none of these steps resolve the issue, feel free to share your full Apache site configuration or the output of ls -la /path/to/your/documentroot—that will help narrow things down further.

内容的提问来源于stack exchange,提问作者stack200 s

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:24:02