【发布时间】:2021-04-04 20:57:33
【问题描述】:
我在 pm2 上运行 nodejs 并在端口 5000 上侦听。如果我在服务器上运行netstat -na |grep 5000,我会得到
tcp 0 0 0.0.0.0:5000 0.0.0.0:* LISTEN
但是当我的 react 应用程序调用 http://localhost:5000/patients 我得到
::ERR_CONNECTION_REFUSED
这是服务器的代码:
const app = express();
const port = process.env.PORT || 5000;
app.use('/patients', require("./routes/patientRoute"));
app.listen(port, "0.0.0.0", () => {
console.log(`server is running on port: ${port}`);
})
从 React 生产构建中,我使用 axios 运行 GET 到 http://localhost:5000/patients 这就是错误发生时
我也在firewalld上打开了端口
【问题讨论】:
-
这可能是一个 selinux 问题。
-
我跑了 setenforce 0 ...它仍然什么也没做
-
我也有同样的问题。你有机会解决它吗?
-
@MarcoGazzin 是的,首先我必须摆脱“0.0.0.0”,然后我将 /api/ 添加到我所有 axios 调用的开头,然后在我需要的 nginx conf 文件中添加
location /api/ { proxy_pass http://127.0.0.1:5000; }.....NGINX 中的位置块是关键!
标签: node.js reactjs axios centos connection-refused