Truy cập vào EC2






Cấu hình networking

#!/bin/bash
#Update the system and install Node.js
yum update -y
curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash -
yum install -y nodejs
#Install PM2 and Express
npm install pm2@latest -g
npm install express --save
#Create and configure the Express app
cat <<'EOF' >> app.js
let express = require('express');
let app = express();
app.get('/api', (req, res) => {
console.log(JSON.stringify(req.headers));
let message = {
timestamp: new Date().toISOString(),
headers: req.headers,
};
res.json(message);
});
app.listen(80, () => {
console.log('api is up!');
});
EOF
#Start the app with PM2
sudo pm2 start ./app.js
sudo pm2 startup systemd
sudo pm2 save
#Enable PM2 to start on system boot
systemctl enable --now pm2-root.service





