查看: 76|回复: 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:dzh188@hotmail.com

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