[英]Setting up react and nodejs servers on same machine
I am setting up a reactjs application on port 3000 as well as a nodejs API server on port 3500 on the same box on the internet.我正在端口 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.
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. On the react code, while calling axios API for a get command, which of the following should I be using:
在反应代码上,在调用 axios API 获取命令时,我应该使用以下哪个:
Few tests I did:我做了几个测试:
If end user is supposed to connect over https to the react server, then the react server as well as the nodejs server should be running in https mode, or the browser will block the request and it will never reach the server.如果最终用户应该通过 https 连接到 react 服务器,那么 react 服务器和 nodejs 服务器应该在 https 模式下运行,否则浏览器将阻止请求并且它永远不会到达服务器。 Here is how to:
以下是如何:
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
Changed the URL for the nodejs server that axios is calling from
http://localhost:3500
to https://example.com:3500
After npm run build, and upload the build directory to the server, run the following commands: 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.