简体   繁体   English

如何在数字海洋上部署create react应用程序?

[英]How to deploy create react app on digital ocean?

Anyone please explain it. 有人请解释一下。

I'm struggling with this.I followed this blogpost https://www.davidmeents.com/blog/how-to-simply-deploy-a-react-app-on-digital-ocean/ But all i got default page of nginx or now after some messing around with configuration i'm getting 404 not found error. 我为此感到挣扎。我关注了这个博客文章https://www.davidmeents.com/blog/how-to-simply-deploy-a-react-app-on-digital-ocean/但我得到的都是默认页面nginx或现在一些混乱的配置后,我得到404 not found错误。

There are two floders inside nginx 1) sites-availble 2)sites-enabled I'm not sure which one is relevant here. nginx内部有两个选件1)可用的站点2)启用了站点我不确定哪一个是相关的。

my config is like this 我的配置是这样的

 server {
    listen 80; 
    server_name 139.59.25.228;
    root /www/mywebsite/app/build;
    rewrite ^/(.*)/$ $1 permanent;
    location / {
       try_files $uri index.html;
    }
}

Thanks -:) 谢谢 -:)

It's not so complicated, you just need to: 它并没有那么复杂,您只需要:

1/ Start your react application as usual, maybe npm start , then maybe it will open port 3000 for you (or any number) 1 /像往常一样启动您的react应用程序,也许是npm start ,那么也许它将为您打开端口3000(或任何数量)

2/ Config nginx for port 80 pointing to that localhost:3000 (or your defined port): 2 /配置指向端口80的nginx指向该localhost:3000 (或您定义的端口):

server {
    listen 80 default_server;
    server_name YOURDOMAIN.HERE;
    location / {
        #auth_basic "Restricted Content";
        #auth_basic_user_file /home/your/basic/auth/passwd_file;
        proxy_pass http://localhost:3000; #or any port number here
        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;
    }
}

However, in order to keep the npm start - your localhost with port 3000 server always alive, I suggest you use pm2 : 但是,为了使npm start保持npm start -端口3000服务器的本地主机始终处于活动状态,建议您使用pm2

sudo npm install pm2 -g

Then, change directory ( cd ) to your reactjs app folder: (I assume you use npm start for starting you reactjs app) 然后,将目录( cd )更改为您的reactjs应用程序文件夹:(我假设您使用npm start来启动reactjs应用程序)

pm2 start npm -- start

(if you use kind of npm run:start to start app, then it should be: pm2 start npm -- run:start ) (如果您使用某种npm run:start来启动应用程序,则应为: pm2 start npm -- run:start

After that, this command will be remembered by pm2 ! 之后,该命令将被pm2记住!

Useful pm2 commands: 有用的pm2命令:

pm2 list all
pm2 stop all
pm2 start all
pm2 delete 0

(use delete 0 to delete the first command from pm2 list with ID 0) (使用delete 0从ID为0的pm2 list删除第一个命令)

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

相关问题 如何在数字海洋上部署 React 应用程序? - How to deploy a react app on digital ocean? 如何通过Passenger / Nginx在数字海洋上部署Django / React / Webpack应用 - How to deploy Django/React/Webpack app on Digital Ocean through Passenger/Nginx 使用 dokku 在 Digital Ocean 上创建反应应用程序部署失败 - Create-react-app deployment failure on Digital Ocean using dokku 我的反应应用在数字海洋上部署后不显示任何内容 - My react app doen't display any content after I deploy it on digital ocean 在数字海洋上的反应应用程序中上传图像 - Uploading image in react app on digital ocean 如何在单个液滴上将不同的 MERN 应用程序部署到数字海洋? - How to deploy different MERN apps to digital ocean on a single droplet? 部署在 Digital Ocean 上的 React App 出现 404 错误 - React App deployed on Digital ocean gives 404 Error 部署在生产环境(Digital Ocean)上的 React App 未在浏览器上加载 - React App deployed on production (Digital Ocean) is not loading on browser React Router 在 Digital Ocean 上失败 - React Router fails on Digital Ocean 当应用托管在Digital Ocean Droplet上时,如何访问Webpack输出? - How to access the webpack output when app hosted on a Digital Ocean droplet?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM