![](/img/trans.png)
[英]Setting up a React application and NodeJS backend in Kubernetes?
[英]Setting up react and nodejs servers on same machine
我正在端口 3000 上设置 reactjs 应用程序,以及在 Internet 上同一个盒子的端口 3500 上设置 nodejs API 服务器。 Assume the box has a domain name example.com, and I am using nginx in reverse proxy to receive the end users over https, and internally direct it to the port 3000 of the reactjs server. 在反应代码上,在调用 axios API 获取命令时,我应该使用以下哪个:
我做了几个测试:
如果最终用户应该通过 https 连接到 react 服务器,那么 react 服务器和 nodejs 服务器应该在 https 模式下运行,否则浏览器将阻止请求并且它永远不会到达服务器。 以下是如何:
proxy_pass https://localhost:3000;
Changed the URL for the nodejs server that axios is calling from http://localhost:3500
to https://example.com:3500
npm运行build后,将build目录上传到服务器,运行如下命令:
su
serve -s build --listen 3000 --ssl-cert "/etc/letsencrypt/live/example.com/fullchain.pem" --ssl-key "/etc/letsencrypt/live/example.com/privkey.pem"
const https = require('https');
const fs = require('fs');
const options = {
key: fs.readFileSync('/etc/letsencrypt/live/example.com/privkey.pem'),
cert: fs.readFileSync('/etc/letsencrypt/live/example.com/fullchain.pem')
};
https.createServer(options, app).listen(PORT, ()=>{
console.log(`Server running https on port ${PORT}`)
});
su
node server
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.