简体   繁体   English

在Amazon Web Server中部署react,node

[英]deploy react ,node in amazon web server

i have deployed my mern stack application to aws ec2 instance.the problem is that my react app is listen to port 3000 and my nodejs app listen to port 5000, and i also used tus-server in node js which is listen at port 8000, how can configure ngnix file. 我已经将我的mern堆栈应用程序部署到了aws ec2实例。问题是我的react应用程序监听了3000端口,而nodejs应用程序监听了5000端口,并且我还在节点js中使用了tus-server,监听了8000端口,如何配置ngnix文件。

server {
    listen 80;
    location / {
        proxy_pass http://PRIVATE_IP_EC2: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;
    }
}

If i run the above configuration in ngnix then only react app is runing, then i could not send any files to nodejs server.what can i do, i want all the ports should run. 如果我在ngnix中运行以上配置,那么只有react app正在运行,那么我无法将任何文件发送到nodejs server。我该怎么办,我希望所有端口都可以运行。

You can add another location in same nginx configuration file with some prefix on which you want to run your app. 您可以在同一nginx配置文件中添加另一个位置,并在其中添加要运行其应用程序的前缀。

For Example if nodejs app's all API url start with /api prefix then you can use as 例如,如果nodejs应用程序的所有API URL都以/ api前缀开头,则可以将其用作

location ^~ /api/ {
   proxy_pass http://PRIVATE_IP_EC2:YOUR_NODEJS_APP_PORT;
   proxy_http_version 1.1;
   proxy_set_header Upgrade $http_upgrade;`enter code here`
   proxy_set_header Connection ‘upgrade’;
   proxy_set_header Host $host;
   proxy_cache_bypass $http_upgrade;
} 

您可以使用您的子域(将指向您的节点应用程序(我想是您的后端))创建另一个nginx配置。然后,在您的react应用程序中,使用您的子域连接到后端API的

I have a feeling that if your React app is listening on port 3000 then you are doing something wrong. 我有一种感觉,如果您的React应用正在监听端口3000,那么您做错了什么。 Isn't it that your create-react-app server is listening on port 3000? 是不是您的create-react-app服务器正在监听端口3000? If so, you should be aware of the fact that this server is mainly for development purpose, not for production. 如果是这样,您应该知道以下事实:该服务器主要用于开发目的,而不是用于生产目的。

If the above is the case then what you should do is to build your React app using npm build command. 如果是这种情况,那么您应该使用npm build命令来build React应用。 Once your static website has been built, you can choose a hosting solution. 建立静态网站后,您可以选择托管解决方案。 The preferred way on AWS is to configure S3 bucket to use website hosting feature (you don't need to set up any web server such as Nginx) and upload contents of the build folder in your React app to that S3 bucket. AWS上的首选方法是将S3存储桶配置为使用网站托管功能(您无需设置任何Web服务器,例如Nginx),并将React应用程序中build文件夹的内容上传到该S3存储桶。 If you choose this route, don't forget to add public read access to your bucket. 如果您选择此路线,请不要忘记为您的存储桶添加公共读取权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Amazon AWS 将 React、Node/Express 和 MySQL web 应用程序部署到 web 应用程序上 - Deploy React, Node/Express, and MySQL web application onto the web with Amazon AWS 如何将Node.js WebSocket服务器部署到Amazon Elastic Beanstalk? - How to deploy a Node.js WebSocket server to Amazon Elastic Beanstalk? 部署不是 web 应用程序的节点服务器 - Deploy Node server that isn't a web application 如何部署node js web服务器? - How to deploy node js web server? 是否可以将“next/react + node/express”web 应用程序部署到一个服务器帐户中,例如 heroku? - Is it possible to deploy “next/react + node/express” web application into one server account, like heroku? 使用 Heroku 部署 React 应用程序 + Node 服务器 - Deploy a React app + Node server with Heroku 无法在 Node JS 服务器上部署 React 应用程序 - Cannot deploy React app at Node JS server cPanel 使用 Node 服务器部署 React webapp - cPanel deploy React webapp with Node server 将 node.js 服务器和 angular 应用程序部署到 azure Z2567A5EC9705EB7AC2C984033E068 服务 - Deploy node.js server and angular app to azure web service 如何将 React App 客户端和 Node Server 部署到 cPanel - How to deploy React App client and Node Server to cPanel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM