查看: 41|回覆: 0

How to Build and Deploy a Next.js App on Apache Server

[複製鏈接]

5

主題

0

回帖

0

積分

热心网友

金币
0
閲讀權限
220
精華
0
威望
0
贡献
0
在線時間
0 小時
註冊時間
2009-2-25
發表於 2024-12-8 20:08:00 | 顯示全部樓層 |閲讀模式

Step 1: Installing Next.js

npm install -g yarn
mkdir -pv /var/www/project_folder_name
cd /var/www/project_folder_name
yarn create next-app

Edit package.json and replace the script section with the following:

"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "NODE_ENV=production node server.js"
},

 

Step 2: Preparing Your Next.js Application for Production

Navigate to your project's root directory and run the following command

cd /var/www/project_folder_name
yarn install
yarn run build

 

Step 3: Configuring Apache

Edit the Apache configuration file, usually located at /etc/httpd/conf/httpd.conf. Add the following lines at the end of the file.

<VirtualHost *:80>
ServerName your-domain.com
ServerAdmin contact@example.com
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
<Directory "/var/www/project_folder_name">
AllowOverride All
</Directory>
</VirtualHost>

Enable the necessary Apache mod_proxy and mod_proxy_http modules

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

httpd -M

Restart Apache to apply the changes.

sudo service httpd restart

 

Step 4: Deploying Your Next.js Application And Keeping Your Application Running

Use yarn to start your Next.js application in production mode.

cd /var/www/project_folder_name
yarn start

 

回覆

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即注册

本版積分規則

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.