VPS

⌘K
  1. Home
  2. VPS
  3. AApanel
  4. Django Deploy AApanel Gunicorn

Django Deploy AApanel Gunicorn

Thought for 1s## aaPanel এ Django + Gunicorn + Nginx – সম্পূর্ণ প্রসেস (Scratch থেকে)


Step 1: aaPanel এ Python Manager Install

  1. aaPanel Dashboard → App Store
  2. Python Project Manager search করে Install করুন
  3. Install হলে Python Project ManagerVersion ManagementPython 3.10 বা 3.12 Install করুন

Step 2: Website তৈরি করুন

  1. aaPanel → WebsiteAdd Site
  2. Domain: screen.ibitltd.com
  3. PHP Version: Pure Static select করুন
  4. Submit করুন

Step 3: SSH দিয়ে Server এ যান এবং Project Setup করুন

# Website folder এ যান
cd /www/wwwroot/screen.ibitltd.com

# Git clone করুন (যদি না করে থাকেন)
git clone https://github.com/your_repo.git .

# Virtual environment তৈরি করুন
python3 -m venv venv

# Activate করুন
source venv/bin/activate

# Dependencies install করুন
pip install --upgrade pip
pip install django gunicorn

# যদি requirements.txt থাকে
pip install -r requirements.txt

# Database migrate করুন
python manage.py migrate

# Static files collect করুন
python manage.py collectstatic --noinput

# Superuser তৈরি করুন (optional)
python manage.py createsuperuser

Step 4: Django Settings Update করুন

config/settings.py (অথবা যেখানে settings.py আছে) file এ:

# ALLOWED_HOSTS এ domain যোগ করুন
ALLOWED_HOSTS = ['screen.ibitltd.com', 'www.screen.ibitltd.com', '127.0.0.1', 'localhost']

# Static files
STATIC_URL = '/static/'
STATIC_ROOT = '/www/wwwroot/screen.ibitltd.com/staticfiles/'

# Media files
MEDIA_URL = '/media/'
MEDIA_ROOT = '/www/wwwroot/screen.ibitltd.com/media/'

# Production এ DEBUG বন্ধ করুন
DEBUG = False

Step 5: Gunicorn Test করুন

# venv activate আছে কিনা নিশ্চিত করুন
source /www/wwwroot/screen.ibitltd.com/venv/bin/activate

# Test run করুন
gunicorn config.wsgi:application --bind 127.0.0.1:8000

# কাজ করলে Ctrl+C দিয়ে বন্ধ করুন

Step 6: Systemd Service তৈরি করুন (Auto Start এর জন্য)

# Service file তৈরি করুন
sudo nano /etc/systemd/system/screen.service

এই content paste করুন:

[Unit]
Description=Screen Django Gunicorn
After=network.target

[Service]
User=www
Group=www
WorkingDirectory=/www/wwwroot/screen.ibitltd.com
Environment="PATH=/www/wwwroot/screen.ibitltd.com/venv/bin"
ExecStart=/www/wwwroot/screen.ibitltd.com/venv/bin/gunicorn config.wsgi:application --bind 127.0.0.1:8000 --workers 3
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target

Save: Ctrl + O → Enter → Ctrl + X

# Daemon reload
sudo systemctl daemon-reload

# Service চালু করুন
sudo systemctl start screen

# Auto start enable করুন
sudo systemctl enable screen

# Status check করুন
sudo systemctl status screen

Step 7: Nginx Reverse Proxy Setup (aaPanel থেকে)

  1. aaPanel → Websitescreen.ibitltd.com click করুন
  2. Reverse Proxy tab এ যান
  3. Add Reverse Proxy click করুন
  4. এই values দিন:
FieldValue
Proxy namedjango
Proxy dir/
Target URLhttp://127.0.0.1:8000
Sent Domain$host
  1. Confirm click করুন

Step 8: Static Files এর জন্য Nginx Config (Optional)

aaPanel → Websitescreen.ibitltd.comConfig

location / { এর আগে এটা যোগ করুন:

location /static/ {
    alias /www/wwwroot/screen.ibitltd.com/staticfiles/;
}

location /media/ {
    alias /www/wwwroot/screen.ibitltd.com/media/;
}

Save করুন।


Step 9: SSL Certificate (HTTPS)

  1. aaPanel → Websitescreen.ibitltd.comSSL
  2. Let’s Encrypt select করুন
  3. Domain tick করুন
  4. Apply click করুন
  5. Force HTTPS enable করুন

কাজের Commands (মনে রাখুন)

# Service চালু
sudo systemctl start screen

# Service বন্ধ
sudo systemctl stop screen

# Service restart
sudo systemctl restart screen

# Status দেখা
sudo systemctl status screen

# Live logs দেখা
sudo journalctl -u screen -f

# Gunicorn process দেখা
ps aux | grep gunicorn

Troubleshooting

# Permission error হলে
sudo chown -R www:www /www/wwwroot/screen.ibitltd.com

# Gunicorn manually test
cd /www/wwwroot/screen.ibitltd.com
source venv/bin/activate
gunicorn config.wsgi:application --bind 127.0.0.1:8000

# Nginx test ও restart
sudo nginx -t
sudo systemctl restart nginx

এই সম্পূর্ণ process follow করলে https://screen.ibitltd.com এ আপনার Django site চলবে এবং server restart হলেও automatically চালু থাকবে।

How can we help?