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

Nginx反向代理localhost:80至localhost:8080失效求助

Troubleshooting Nginx Reverse Proxy Not Working

Hey, I’ve run into this exact issue when setting up my first Nginx reverse proxy—let’s walk through the most common fixes to get your proxy working:

1. The Default Nginx Config Is Likely Taking Over

Nginx comes with a default default.conf file (usually in /etc/nginx/conf.d/ or /etc/nginx/sites-enabled/) that also listens on port 80. This default config is probably overriding your custom proxy setup. Here’s how to fix it:

  • Disable the default config: Rename it so Nginx doesn’t load it anymore:
    sudo mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
    
  • Or add a server_name to your config: Specify that your server block handles requests for localhost, which gives it higher priority than the default catch-all config. Update your server block like this:
    server {
        listen 80;
        server_name localhost;
        location / {
            proxy_pass http://localhost:8080;
        }
    }
    

2. Make Sure Your Config File Is Actually Loaded by Nginx

If you saved your config in a non-standard location (like /etc/nginx/sites-available/ instead of /etc/nginx/conf.d/), Nginx might not be reading it:

  • Create a symbolic link from sites-available to sites-enabled (Nginx checks this directory for active configs):
    sudo ln -s /etc/nginx/sites-available/your-proxy.conf /etc/nginx/sites-enabled/
    
  • Double-check your main nginx.conf file to ensure it includes the directories where your config lives. Look for lines like these:
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
    

3. You Forgot to Reload/Restart Nginx After Changing Configs

This is the most common mistake! After editing your config, you need to tell Nginx to apply the changes:

  • First, validate your config to catch any syntax errors:
    sudo nginx -t
    
  • If you see nginx: configuration file /etc/nginx/nginx.conf test is successful, reload Nginx:
    sudo nginx -s reload
    
  • If reload doesn’t work, restart the entire service:
    sudo systemctl restart nginx
    

4. Verify Port 80 Is Actually Being Listened On by Nginx

It’s possible another process is hogging port 80, so Nginx can’t listen on it. Check which process is using port 80:

sudo lsof -i :80

If you see something other than nginx in the output, you’ll need to stop that process or adjust Nginx to listen on a different port (though port 80 is standard for HTTP).

Go through these steps one by one—9 times out of 10, it’s either the default config interfering or forgetting to reload Nginx. I fixed my first proxy issue by just disabling the default config and reloading, so fingers crossed this works for you!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.13 08:55:48