Bạn có biết?
Bạn có bao giờ deploy một ứng dụng Node.js lên server, rồi phải cài đặt nginx, cấu hình proxy, systemd services, và tự hỏi "sao phải phức tạp vậy không?"
Với Docker, bạn chỉ cần một file docker-compose.yml — chạy nginx + Node.js + database trong vài giây!
Kiến trúc Web App đơn giản
Chúng ta sẽ deploy một web app có:
- ✅ Node.js API — Express server xử lý business logic
- ✅ Nginx — Reverse proxy và static files
- ✅ Giao tiếp — Nginx forward requests tới Node.js
Project Structure
my-webapp/
├── docker-compose.yml
├── nginx/
│ └── default.conf
├── app/
│ ├── package.json
│ ├── index.js
│ └── Dockerfile
└── public/
└── index.html
Node.js App
1. package.json
{
"name": "my-webapp",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"express": "^4.18.2"
}
}
2. index.js
const express = require();
app = ();
= process.. || ;
app.(express.());
app.(, {
res.({ : });
});
app.(, {
res.({ : });
});
app.(, {
.();
});
0 bình luận
Đang tải bình luận...
Để lại bình luận