[英]How can I deploy nextjs and nodejs on Heroku without using npm run build on the client/frontend side?
[英]NextJS Deployment - How can I simply deploy NextJS like NodeJS on Ubuntu server?
為了部署 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
=========================================
如何在 ubuntu 服務器上通過 systemd 部署 NextJS?
提前致謝。
我正在使用以下單元文件運行它:
[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
WorkingDirectory
應該指向 NextJS 項目所在的目錄。
npm install
安裝node_modules
中的依賴項(duh)。 npm run build
編譯了一些東西,最終以static/
npm run start
啟動NodeJS服務器。
很多人建議使用pm2
,但我不喜歡它。 如果您使用 CDI,您可以獲得npm run build
並將npm install
到構建過程中,然后提取工件(下面提到的文件/文件夾)。
考慮到 NextJS 的工作方式,您可能只需要以下文件和文件夾: node_modules/ static/ package.json package-lock.json next.config.js
。 雖然,這也取決於您的項目。
當然,這對於生產服務器來說還遠遠不夠。 特別是,因為您需要設置一個像 Nginx 或 Apache 這樣的網絡服務器,以便為您的 NextJS 應用程序執行location
代理傳遞。 這是因為 NextJS 應用程序在Localhost:PORT
下運行。
資料來源:痛苦的經歷。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.