Gunicorn 서비스 파일

/etc/systemd/system/gunicorm.service

[Unit]
Description=Gunicorn daemon for Django Project
After=network.target

[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/AInfo-backend
ExecStart=/path/to/your/venv/bin/gunicorn --workers 3 --bind 127.0.0.1:8000 config.wsgi:application
Restart=always

[Install]
WantedBy=multi-user.target

Daphne 서비스 파일

/etc/systemd/system/daphne.service

[Unit]
Description=Daphne ASGI Server for Django Channels
After=network.target

[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/AInfo-backend
ExecStart=/path/to/your/venv/bin/daphne -b 127.0.0.1 -p 9000 config.asgi:application
Restart=always

[Install]
WantedBy=multi-user.target

nginx.conf

server {
    listen 80;
    server_name ainfo.ai.kr

    # 정적 파일 제공 (Django collectstatic 사용)
    location /static/ {
        root /home/ubuntu/AInfo-backend;
        expires 30d;
    }

    location /media/ {
        root /home/ubuntu/AInfo-backend;
        expires 30d;
    }

    # Django(Gunicorn)로 요청 전달
    location / {
        proxy_pass http://127.0.0.1:8000;  # Gunicorn 실행 포트
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    # WebSocket (Daphne)로 요청 전달
    location /ws/ {
        proxy_pass http://127.0.0.1:9000;  # Daphne 실행 포트
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}