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

Ubuntu 16.04 LTS下Apache多域名无法访问,提示ERR_CONNECTION_TIMED_OUT求助

Troubleshooting Your Apache & Domain Issues on Ubuntu 16.04 LTS

Hey there! Let's work through your two main issues—domain timeouts and only seeing one site internally—step by step.

1. Fixing ERR_CONNECTION_TIMED_OUT for Your Domains

This usually boils down to dynamic IP sync issues, firewall blocks, or ISP restrictions. Here's what to check:

  • Verify Namecheap Dynamic DNS is Updating Your IP
    Since you're using a dynamic public IP, Namecheap needs real-time updates when your IP changes. Set up a simple auto-update script on Ubuntu to keep things in sync:

    # Create a script (replace placeholders with your domain and Namecheap DDNS password)
    sudo nano /usr/local/bin/update-namecheap-dns.sh
    

    Paste this into the script:

    #!/bin/bash
    DOMAIN="yourdomain.com"
    PASSWORD="your_ddns_password_from_namecheap"
    curl "https://dynamicdns.park-your-domain.com/update?host=@&domain=$DOMAIN&password=$PASSWORD"
    

    Make it executable:

    sudo chmod +x /usr/local/bin/update-namecheap-dns.sh
    

    Add a cron job to run it every 15 minutes:

    crontab -e
    

    Add this line at the bottom:

    */15 * * * * /usr/local/bin/update-namecheap-dns.sh
    

    Save and exit—this ensures your Namecheap records always match your current public IP.

  • Check Firewalls (Ubuntu & Router)

    • On Ubuntu, confirm UFW allows port 80:
      sudo ufw status
      
      If "80/tcp" isn't listed as allowed, run:
      sudo ufw allow 80/tcp
      
    • Double-check your router's port forwarding rule for 80 → 10.0.0.111—make sure it's enabled and targeting the correct internal IP. Some ISPs block port 80 by default: test this by temporarily forwarding port 8080 to your Ubuntu machine and accessing yourdomain.com:8080 from your phone's 4G network. If that works, your ISP is blocking 80, and you'll need to use an alternative port or request unblocking.
  • Confirm Public IP Accessibility
    On your Ubuntu machine, run curl ifconfig.me to get your current public IP. Visit that IP directly from your phone's 4G (e.g., http://123.45.67.89). If this times out too, the issue is with your router's forwarding or ISP restrictions, not Apache.

2. Making All Sites Accessible Internally

Right now, Apache is serving its default site when you visit 10.0.0.111 because you haven't set up virtual hosts to map each domain to its own content. Here's how to fix that:

  • Create Site Directories & Set Permissions
    For each domain, make a root directory for its files:

    # Replace with your actual domains
    sudo mkdir -p /var/www/yourfirstdomain.com/public_html
    sudo mkdir -p /var/www/yourseconddomain.com/public_html
    sudo mkdir -p /var/www/yourthirddomain.com/public_html
    

    Set ownership so you can edit files without sudo:

    sudo chown -R $USER:$USER /var/www/yourfirstdomain.com/public_html
    sudo chown -R $USER:$USER /var/www/yourseconddomain.com/public_html
    sudo chown -R $USER:$USER /var/www/yourthirddomain.com/public_html
    sudo chmod -R 755 /var/www
    

    Add unique index.html files to each public_html folder so you can distinguish the sites.

  • Set Up Apache Virtual Hosts
    Copy the default config as a template for each domain:

    sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/yourfirstdomain.com.conf
    sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/yourseconddomain.com.conf
    sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/yourthirddomain.com.conf
    

    Edit each config file (replace with your domain):

    sudo nano /etc/apache2/sites-available/yourfirstdomain.com.conf
    

    Modify it to look like this:

    <VirtualHost *:80>
        ServerAdmin webmaster@yourfirstdomain.com
        ServerName yourfirstdomain.com
        ServerAlias www.yourfirstdomain.com
        DocumentRoot /var/www/yourfirstdomain.com/public_html
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
    

    Repeat this for your other two domains.

  • Enable the Sites & Restart Apache
    Enable each virtual host config:

    sudo a2ensite yourfirstdomain.com.conf
    sudo a2ensite yourseconddomain.com.conf
    sudo a2ensite yourthirddomain.com.conf
    

    Disable the default site to avoid conflicts (optional but recommended):

    sudo a2dissite 000-default.conf
    

    Restart Apache to apply changes:

    sudo systemctl restart apache2
    
  • Test Internally with Hosts File
    To test domains from your Windows 10 machine, map them to the Ubuntu internal IP via the hosts file:

    1. Open Notepad as Administrator.
    2. Open C:\Windows\System32\drivers\etc\hosts.
    3. Add these lines at the bottom (replace with your domains):
      10.0.0.111 yourfirstdomain.com
      10.0.0.111 yourseconddomain.com
      10.0.0.111 yourthirddomain.com
      
    4. Save the file. Now visiting each domain in your Windows browser will load the corresponding site.

内容的提问来源于stack exchange,提问作者Michael H Graf Sr.

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 08:35:36