1. Nhu cầu và giải pháp
- Nhu cầu: giữa các mạng an toàn như VDI cần 1 phương thức chuyển thông tin đến nhau. 1 trong các phương thức đơn giản là dùng 1 giao diện notepad trên web. Cách này không thực sự bảo mật (thông tin quan trọng có thể bị paste lên) → Chỉ nên sử dụng nếu chưa có phương án nào tốt hơn.
- Giải pháp: Dựng 1 webapp đơn giản cho phép paste text lên web url
2. Các bước thực hiện
a. Tạo thư mục ./src và lấy webapp về, ví dụ GitHub - pereorga/minimalist-web-notepad: Minimalist Web Notepad
mkdir src
cd src
git pull https://github.com/pereorga/minimalist-web-notepad .
-
Đổi quyền về www-data cho thư mục đó
sudo chown -R www-data:www-data ./src -
Sửa file index.php để đưa url đúng vào
// Base URL of the website, without trailing slash.
$base_url = 'https://np.nxcom.vn';
- Tạo file cấu hình apache cho site, ví dụ note.conf trong thư mục gốc của docker
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName np.nxcom.vn
DocumentRoot /var/www/note
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/note/>
AllowOverride All
</Directory>
</VirtualHost>
b. Tạo Docker file và build 1 docker image đơn giản, trong đó chứa app pastebin đơn giản kia (vd. lưu ở ./src. Nội dung Dockerfile
FROM php:8.2-apache
# Enable mod_rewrite (nếu cần)
RUN a2enmod rewrite
COPY note.conf /etc/apache2/sites-enabled/
# Set quyền
RUN chown -R www-data:www-data /var/www/html
EXPOSE 80
Build docker image
sudo docker build -t notepad .
c. Tạo docker compose file
version: "3.9"
services:
notepad:
container_name: notepad
build: .
restart: unless-stopped
ports:
- "8081:80"
volumes:
- ./src:/var/www/note
- Cấu hình reverse proxy để kết nối tới docker, cổng 8081