无法使用NPM运行构建运行NextJS
我最近在Digitalocean服务器上部署了一个React静态应用程序。我所做的只是在nginx配置文件中显示构建文件的根目录。而且运行良好。
现在,我试图在服务器上托管一个NextJS应用程序。我显示了root目录root/var/www/html/nextjstestapp/.next
我什至尝试了root/var/var/var/www/html/nextjstestapp/node_modules
当我运行npm run build
完成构建时,我尝试到达服务器,它显示“ 502 BAD GATEWAY”,
但是当我运行npm start
时 站点图像 该应用程序正在显示
我可以一直在运行它的操作吗?我正在使用digitalocean液滴。
I recently deployed a react static app on my digitalocean server. All I did was show the root directory of the build file in the Nginx config file. And it's running well.
Now I am trying to host a NextJS app on my server. I showed the root directory root /var/www/html/NextJSTestApp/.next
I even tried with root /var/www/html/NextJSTestApp/node_modules
When I am running the npm run build
the build is done then I tried to reach my server it's showing "502 Bad Gateway"
But when I am running npm start
site image
The app is showing
What I can do to run it all the time? I am using digitalocean droplet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当运行NextJS作为节点应用程序(例如下一个启动)时,您需要将NGINX设置为使用
proxy_pass
而不是将其指向根目录(省略根指令)。示例nginx位置块
When running NextJS as a node application (e.g. next start), you need to set nginx to use
proxy_pass
instead of pointing it to a root directory (omit root directive).Example nginx location block
首先,一旦您关闭终端或留下bash,手动运行
下一个启动
就不会持续存在。为了让其在后台运行,您可以使用&&在开始命令的末尾(下一个启动&&)或创建一个SystemD文件(建议)。其次,一旦您完成了在后台运行的nextJ,就可以继续并设置代理通行证到您的Web服务器(nginx,apache ...)
First, Manually running
next start
does not persist the process once you close the terminal or leave the bash. In order to let it run in the background, you may use && at the end of start command (next start &&) or create a systemd file (recommended).Second, Once you are done with a nextJs running on background, you can go ahead and setup a proxy pass to your web server(nginx, apache ...)
我找到了这个解决方案。为了运行这个项目背景,我使用了PM2。
sudo npm install -G pm2
然后转到我的项目文件夹
CD网站/
pm2开始-name = nebs npm -start
然后
pm2 startup startup systemd
我遵循此 tutorial
I found this solution. To run this project background I used pm2.
sudo npm install -g pm2
Then gone to my project folder
cd website/
pm2 start --name=website npm -- start
then
pm2 startup systemd
I followed this tutorial