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

Ubuntu 17.10下Nginx虚拟主机配置失效问题求助

Troubleshooting test.app Virtual Host Issue on Ubuntu 17.10 + Nginx

Hey there, let's walk through fixing this issue—virtual host misconfigurations can be tricky but usually boil down to a few common checks. Here's what to verify step by step:

1. Confirm Your hosts File Changes Are Active

First, let's make sure your hosts entry is actually being used. Sometimes DNS caches can hold onto old records, or formatting issues in the file can break resolution:

  • Run ping test.app in your terminal. You should see output showing it's resolving to 127.0.0.1. If not:
    • Flush the system DNS cache with: sudo systemd-resolve --flush-caches
    • Or restart the resolver service entirely: sudo systemctl restart systemd-resolved
  • Double-check your /etc/hosts file formatting—your current entry merges localhost and test.app on one line, which can cause inconsistencies. Split them into separate lines like this:
    127.0.0.1 localhost
    127.0.0.1 test.app
    127.0.1.1 Flashy-PC
    # The following lines are desirable for IPv6 capable hosts
    ::1 ip6-localhost ip6-loopback
    fe00::0 ip6-localnet
    ff00::0 ip6-mcastprefix
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters
    

2. Verify Nginx Virtual Host Configuration

Next, let's ensure your Nginx config for test.app is properly set up:

  • Check if you have a config file in /etc/nginx/sites-available/ for test.app. If not, create one with:
    server {
        listen 80;
        server_name test.app;
    
        # Replace this with your actual website root directory
        root /var/www/test.app;
        index index.html index.htm;
    
        location / {
            try_files $uri $uri/ =404;
        }
    }
    
  • Enable the site by creating a symbolic link: sudo ln -s /etc/nginx/sites-available/test.app /etc/nginx/sites-enabled/
  • Critical: Test for Nginx syntax errors with: sudo nginx -t. If you get any errors (like missing semicolons or invalid paths), fix them before proceeding.

3. Restart Nginx & Check Service Status

After fixing any config errors, restart Nginx to apply changes:

  • sudo systemctl restart nginx
  • Verify the service is running: sudo systemctl status nginx—it should show "active (running)" in green.

4. Check Firewall Settings

Ubuntu 17.10 uses ufw by default. Make sure port 80 (HTTP) is open to allow traffic:

  • Run sudo ufw status. Look for a line like 80/tcp ALLOW Anywhere
  • If port 80 isn't allowed, open it with: sudo ufw allow 80/tcp

5. Clear Browser Cache

Sometimes your browser caches old DNS data or failed requests. Try accessing test.app in incognito/private mode, or clear your browser's cache and cookies to rule this out.

6. Dig Deeper with Nginx Logs

If all the above steps don't work, check Nginx's error logs to pinpoint the exact issue:

  • Run sudo tail -f /var/log/nginx/error.log and then try accessing test.app in your browser. The log will show specific errors (like permission issues, missing files, or config mistakes) that you can address directly.

Bonus: Fix Directory Permissions

Ensure the Nginx user (www-data) has access to your website root directory:

  • sudo chown -R www-data:www-data /var/www/test.app
  • sudo chmod -R 755 /var/www/test.app

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 06:22:02