- Ubuntu Server (18.04 ขึ้นไป)
- Nginx ติดตั้งแล้ว
- Git ติดตั้งแล้ว
- สิทธิ์ sudo
sudo apt update
sudo apt install git -y2. สร้าง SSH Key สำหรับ GitHub (ถ้าใช้ git@github.com)
# สร้าง SSH key
ssh-keygen -t ed25519 -C "your_email@example.com"
# คัดลอก public key
cat ~/.ssh/id_ed25519.pubจากนั้นเพิ่ม SSH key ไปที่ GitHub:
- ไปที่ https://github.com/settings/keys
- คลิก "New SSH key"
- วาง public key ที่คัดลอกมา
# สร้างโฟลเดอร์สำหรับเว็บไซต์
sudo mkdir -p /var/www/opengisdata
sudo chown -R $USER:$USER /var/www/opengisdatacd /var/www/opengisdata
git clone git@github.com:chingchai/OpenGISData-Thailand.git
cd OpenGISData-Thailandสร้างไฟล์ config สำหรับ nginx:
sudo nano /etc/nginx/sites-available/opengisdataวางข้อมูลนี้:
server {
listen 80;
server_name your-domain.com; # เปลี่ยนเป็น domain ของคุณ
root /var/www/opengisdata/OpenGISData-Thailand;
index index.html;
location / {
try_files $uri $uri/ =404;
# Enable CORS for GeoJSON files
if ($request_filename ~* \.(geojson)$) {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
}
}
# Cache GeoJSON files
location ~* \.geojson$ {
expires 1d;
add_header Cache-Control "public, immutable";
add_header Access-Control-Allow-Origin *;
}
# Compression for JSON files
gzip on;
gzip_types application/json application/geo+json;
gzip_min_length 1000;
}# สร้าง symbolic link
sudo ln -s /etc/nginx/sites-available/opengisdata /etc/nginx/sites-enabled/
# ตรวจสอบ config
sudo nginx -t
# Reload nginx
sudo systemctl reload nginxcd /var/www/opengisdata/OpenGISData-Thailand
git pull origin masterดูไฟล์ deploy.sh ที่มาพร้อมกัน:
# ให้สิทธิ์ execute
chmod +x deploy.sh
# รันสคริปต์
./deploy.sh# แก้ไข crontab
crontab -e
# เพิ่มบรรทัดนี้เพื่ออัพเดททุกวันเวลา 3:00 น.
0 3 * * * cd /var/www/opengisdata/OpenGISData-Thailand && git pull origin master >> /var/log/git-pull.log 2>&1sudo systemctl status nginx# ทดสอบจาก localhost
curl http://localhost/provinces.geojson
# หรือเปิดจาก browser
# http://your-domain.com/provinces.geojsoncd /var/www/opengisdata/OpenGISData-Thailand
git status
git log -1 # ดู commit ล่าสุดsudo chown -R www-data:www-data /var/www/opengisdata/OpenGISData-Thailandcd /var/www/opengisdata/OpenGISData-Thailand
git fetch origin
git reset --hard origin/master# ดู log
sudo tail -f /var/log/nginx/error.log
# ตรวจสอบ config
sudo nginx -tข้อมูล GeoJSON สามารถเข้าถึงได้ผ่าน URL:
http://your-domain.com/provinces.geojson- ข้อมูลจังหวัด 77 จังหวัดhttp://your-domain.com/districts.geojson- ข้อมูลอำเภอ 928 อำเภอhttp://your-domain.com/subdistricts.geojson- ข้อมูลตำบล 7,367 ตำบลhttp://your-domain.com/reg_royin.geojson- ภูมิภาค 7 ภูมิภาคhttp://your-domain.com/reg_nesdb.geojson- ภูมิภาค 6 ภูมิภาค
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d your-domain.com