![](/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.