[英]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.