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

Linode上React Router 7 SSR应用Nginx反向代理访问问题

排查与解决步骤

1. 修正域名匹配规则

你的Nginx配置里server_name仅指定了mydomain.com,但实际访问的是www.mydomain.com,Nginx找不到匹配的server块时会自动使用默认欢迎页配置。请修改配置,同时包含主域名和www子域名:

server {
    listen 80;
    server_name mydomain.com www.mydomain.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

2. 禁用Nginx默认欢迎页配置

Ubuntu系统中,Nginx默认会在/etc/nginx/sites-enabled/目录下保留一个default配置文件,该配置会匹配所有未被自定义规则覆盖的请求。执行以下命令禁用它:

sudo unlink /etc/nginx/sites-enabled/default

3. 确保自定义配置已启用

如果你的配置文件存放在/etc/nginx/sites-available/目录下,需要创建软链接到/etc/nginx/sites-enabled/目录才能生效:

sudo ln -s /etc/nginx/sites-available/你的配置文件名 /etc/nginx/sites-enabled/

4. 验证配置并重启Nginx

每次修改配置后,先检查语法正确性:

sudo nginx -t

若输出test is successful,再重启Nginx使配置生效:

sudo systemctl restart nginx

5. 检查Node.js应用监听地址

确认你的Express应用监听的是0.0.0.0:3000而非仅localhost:3000(虽然localhost也能被代理,但部分场景下会出现访问异常),代码中需确保类似如下监听逻辑:

app.listen(3000, '0.0.0.0', () => {
  console.log('Server running on port 3000');
});

6. 检查防火墙规则

确保Ubuntu的ufw防火墙允许80端口的流量:

sudo ufw allow 80/tcp
sudo ufw reload

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 23:43:12