英文:
React production build on Linux server
问题
当我关闭Putty后运行'serve -s build'会话停止,我的React应用程序停止工作。
你好!
我创建了一个小型的React应用程序,使用create-react-app创建。我想将这个应用程序部署到Linux服务器上,所以我使用npm run build命令,它会创建一个'build'文件夹。然后,我将'build'文件夹移动到服务器上,并使用serve -s build命令。应用程序运行正常,但有一个问题 - 当我关闭Putty(我用它来连接到服务器)时,会话关闭并且React应用程序停止工作。我尝试使用类似这样的命令serve -s build &,但没有帮助,每次关闭会话时应用程序都会停止。
请问你能帮助并澄清在服务器上部署React应用程序的正确方法是什么吗?如何使其在关闭Putty后仍然工作?
谢谢你的时间。
英文:
When I close putty after running 'serve -s build' session stops and my React app stops working
Hello!
I created a small React application using create-react-app. I want to deploy this app on Linux server, so I use the command npm run build, which creates 'build' folder. Then I move 'build' folder to server and use the command serve -s build. The app works fine, but there's the problem - when I close putty (which I use to connect to my server) session closes and React app stops. I tried to use the command like this serve -s build &, but that doesn't help and every time I close the session the app stops
Could you please help and clarify what is the right way to deploy React app on server? How to make it work even when I close putty?
Thanks for your time
答案1
得分: 0
感谢Konrad的评论,我最终意识到问题不在于React命令,而是在后台运行进程中。使用serve -s build &
和nohup serve -s build > f1.txt &
没有帮助,但当我开始搜索正确的术语时,我找到了这个答案这里。
<br>这个链接也帮助了很多。
所以,在阅读了这些文章后,我的步骤是:
nohup serve -s build > f1.txt &
jobs -l
*我的进程ID是1*
disown %1
英文:
Thanks to the comment by Konrad I finally realized that the problem was not with the React command, but in running processes in background mode. Using serve -s build & and nohup serve -s build > f1.txt &
didn't help, but when I started searching for the right terms I found this answer here.
<br>This link helped a lot as well.
So after reading the articles my steps were:
nohup serve -s build > f1.txt &
jobs -l
*the id of my process was 1*
disown %1
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论