Skip to content

Commit 5603376

Browse files
author
Jonathan Visser
committed
Add hypernode docs for NextJS example
1 parent f35edbf commit 5603376

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Config for Magento 2
2+
3+
```{note}
4+
NextJS is not officially supported on the Hypernode Platform. So please use this at your own risk,.
5+
```
6+
7+
Configuration to use as Hypernode Deploy deploy.php for a NextJS webserver application:
8+
9+
```php
10+
<?php
11+
12+
declare(strict_types=1);
13+
14+
namespace Hypernode\DeployConfiguration;
15+
16+
use function Deployer\run;
17+
use function Deployer\task;
18+
use function Deployer\test;
19+
use function Deployer\within;
20+
21+
task('node:install', static function () {
22+
run('npm ci');
23+
});
24+
25+
task('node:build', static function () {
26+
run('npm run build');
27+
});
28+
29+
task('deploy:pm2:install', static function() {
30+
if (!test('grep -q "/data/web/.local/bin" ~/.bashrc')) {
31+
run('echo "export PATH=/data/web/.local/bin:$PATH" >> ~/.bashrc');
32+
run('source ~/.bashrc');
33+
}
34+
35+
run('npm install -g pm2 --prefix /data/web/.local');
36+
});
37+
38+
task('deploy:pm2:restart', static function() {
39+
within('{{release_path}}', function () {
40+
run('pm2 startOrRestart ecosystem.config.js --env prod');
41+
});
42+
});
43+
44+
$configuration = new Configuration();
45+
46+
$configuration->setPlatformConfigurations([
47+
new PlatformConfiguration\NginxConfiguration('etc/nginx'),
48+
new PlatformConfiguration\HypernodeSettingConfiguration('supervisor_enabled', 'False'),
49+
new PlatformConfiguration\HypernodeSettingConfiguration('rabbitmq_enabled', 'False'),
50+
new PlatformConfiguration\HypernodeSettingConfiguration('elasticsearch_enabled', 'False'),
51+
new PlatformConfiguration\HypernodeSettingConfiguration('opensearch_enabled', 'False'),
52+
new PlatformConfiguration\HypernodeSettingConfiguration('varnish_enabled', 'False'),
53+
new PlatformConfiguration\HypernodeSettingConfiguration('nodejs_version', '20'),
54+
]);
55+
56+
$configuration->addBuildTask('node:env');
57+
$configuration->addBuildTask('node:install');
58+
$configuration->addBuildTask('node:build');
59+
60+
$configuration->addDeployTask('deploy:pm2:install');
61+
$configuration->addDeployTask('deploy:pm2:restart');
62+
63+
$configuration->setSharedFiles([
64+
'.env'
65+
]);
66+
67+
$configuration->setDeployExclude([
68+
'./.git',
69+
'./deploy.php',
70+
'.gitignore',
71+
'./etc'
72+
]);
73+
74+
$productionStage = $configuration->addStage('production', 'my-next-application.nl');
75+
$productionStage->addServer('app.hypernode.io');
76+
77+
$acceptanceStage = $configuration->addStage('acceptance', 'my-next-application.nl');
78+
$acceptanceStage->addBrancherServer('app')
79+
->setLabels(['stage=acceptance']);
80+
81+
return $configuration;
82+
```
83+
84+
This will:
85+
86+
- Configure the Hypernode settings optimal for the least load of non-used applications and servers.
87+
- Install [PM2](https://pm2.keymetrics.io/) if not present on the server.
88+
- Sets up a vhost for application.
89+
- Sets up the nginx configuration to proxy to the NextJS server.
90+
91+
You will still need to add the nginx configuration file, so create the `./etc/nginx/server.headless.conf` file:
92+
93+
```nginx
94+
location / {
95+
proxy_pass http://localhost:3000;
96+
proxy_http_version 1.1;
97+
proxy_set_header Upgrade $http_upgrade;
98+
proxy_set_header Connection 'upgrade';
99+
proxy_set_header Host $host;
100+
proxy_set_header X-Real-IP $remote_addr;
101+
proxy_cache_bypass $http_upgrade;
102+
103+
# Optional: set maximum response time to 60 seconds
104+
proxy_read_timeout 60s;
105+
proxy_connect_timeout 60s;
106+
}
107+
108+
# Optional: specific location for static assets if they are served by Next.js
109+
location /_next/ {
110+
proxy_pass http://localhost:3000;
111+
proxy_cache_bypass $http_upgrade;
112+
}
113+
```
114+
115+
And to save configuration about pm2, add the `ecosystem.config.js` file:
116+
117+
```
118+
module.exports = {
119+
apps: [
120+
{
121+
name: 'my-next-app',
122+
exec_mode: 'cluster',
123+
instances: 'max', // Or a number of instances
124+
script: 'node_modules/next/dist/bin/next',
125+
args: 'start'
126+
}
127+
]
128+
}
129+
```

0 commit comments

Comments
 (0)