简体   繁体   English

NextJS 部署 - 如何在 Ubuntu 服务器上简单地部署 NextJS,如 NodeJS?

[英]NextJS Deployment - How can I simply deploy NextJS like NodeJS on Ubuntu server?

To deploy NodeJS, I use systemd and configure /lib/systemd/system/[service_name].service file为了部署 NodeJS,我使用 systemd 并配置 /lib/systemd/system/[service_name].service 文件

======================================== =========================================

[Unit]
Description=Inventory Management System
Documentation=PLM Inventory Management Documents
After=network.target

[Service]
Environment=NODE_PORT=3000
Type=simple
User=superuser
WorkingDirectory=/home/superuser/inventory
ExecStart=/home/superuser/.npm-global/bin/nodemon --exec babel-node /home/superuser/inventory/server/server.js
Restart=on-failure

[Install]
WantedBy=multi-user.target

======================================== =========================================

How can I deploy NextJS by systemd on ubuntu server?如何在 ubuntu 服务器上通过 systemd 部署 NextJS?

Thanks in advance.提前致谢。

I am running it with the following unit file:我正在使用以下单元文件运行它:

[Unit]
Description=NodeJS server, NextJS public frontend
After=network.target

[Service]
Type=simple
User=someuser
Group=someuser
Restart=on-failure
RestartSec=10
WorkingDirectory=/some/dir/
ExecStartPre=/usr/bin/npm install
ExecStartPre=/usr/bin/npm run build
ExecStart=/usr/bin/npm run start

[Install]
WantedBy=multi-user.target

The WorkingDirectory should point to the directory, where your NextJS project is. WorkingDirectory应该指向 NextJS 项目所在的目录。

npm install installs the dependencies in node_modules (duh). npm install安装node_modules中的依赖项(duh)。 npm run build compiles some stuff, that ends up as static/ npm run start starts the NodeJS server. npm run build编译了一些东西,最终以static/ npm run start启动NodeJS服务器。

A lot of people suggest using pm2 , but i am not a fan of it.很多人建议使用pm2 ,但我不喜欢它。 If you are using CDI, you can get the npm run build and npm install into the build process, and then extract the artifacts (the file/folders mentioned below).如果您使用 CDI,您可以获得npm run build并将npm install到构建过程中,然后提取工件(下面提到的文件/文件夹)。

Considering the way NextJS works, you should probably only need the following files and folders: node_modules/ static/ package.json package-lock.json next.config.js .考虑到 NextJS 的工作方式,您可能只需要以下文件和文件夹: node_modules/ static/ package.json package-lock.json next.config.js Although, this too depends on your project.虽然,这也取决于您的项目。

Ofcourse, this is not nearly enough for production servers.当然,这对于生产服务器来说还远远不够。 Especially, since you will need to setup an webserver like Nginx or Apache, in order to do the location Proxy Pass to your NextJS application.特别是,因为您需要设置一个像 Nginx 或 Apache 这样的网络服务器,以便为您的 NextJS 应用程序执行location代理传递。 This is because, the NextJS application is running under Localhost:PORT .这是因为 NextJS 应用程序在Localhost:PORT下运行。

Source: painful experience with this.资料来源:痛苦的经历。

暂无
暂无

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

相关问题 如何在 Heroku 上部署 nextjs 和 nodejs 而不使用 npm 在客户端/前端运行构建? - How can I deploy nextjs and nodejs on Heroku without using npm run build on the client/frontend side? 如何保存从 NextJS 客户端发送的图像到我的 NodeJS 服务器? - How can I save an image sent from my NextJS client to my NodeJS server? 如何将我的 nextjs typescript(接口/类型)与 nodejs 服务器 typescript 模型(接口/类型)一起保存? - How I can keep my nextjs typescript (interfaces / types) with nodejs server typescript models (interfaces / types)? 如何使用 nextjs、node 和solid library 安装一个solid server? - How can I mount a solid server with nextjs, node, and solid library? 如何将 NextJS 应用程序部署到 Linux 服务器 (CentOS 7) - VPS - How to deploy NextJS application to Linux Server (CentOS 7) - VPS 如何在 FTP 服务器上部署我的 NextJS web 应用程序而不丢失 SSR 页面? - How can I deploy my NextJS web app on FTP Servers and not lose the SSR pages? React:NextJS,我需要两台服务器进行部署吗? - React: NextJS, do I need 2 servers for deployment? 如何获取对 Nextjs 服务器的引用 - How to get a reference to the Nextjs server 如何将nextjs部署到非根目录的目录中 - How to deploy nextjs into a directory which is not a root directory 我如何编写一个函数来调用(POST)一个 API,从 Web 服务器而不是浏览器。 -NextJS - How can i write a function to call(POST) an API, from within the web server and not the browser. -NextJS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM