$ pip install gunicorn
$ gunicorn --bind 0.0.0.0:8000 [wsgi.py가 들어있는 폴더].wsgi:application
$ vi /etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=ubuntu
Group=www-data
WorkingDirectory=[프로젝트 경로] ex) /home/ubuntu/my_project
ExecStart=[gunicorn 설치 경로] --workers 3 --bind 0.0.0.0:8000 [wsgi.py가 들어있는 폴더].wsgi:application
[Install]
WantedBy=multi-user.target
gunicorn 설치경로는
$ whereis gunicorn
으로 알 수 있다.
$ systemctl start gunicorn
$ systemctl enable gunicorn
$ systemctl status gunicorn.service
$ apt-get update
$ apt-get install nginx
server {
listen 80;
server_name [내 aws 서버 ip 주소];
charset utf-8;
client_max_body_size 128M;
location = /favicon.ico { access_log off; log_not_found off; }
location / {
include proxy_params;
# gunicorn ip 및 포트 번호
proxy_pass http://127.0.0.1:8000;
}
location /static/ {
alias /home/ubuntu/my_project/static/;
}
location /media/ {
alias /home/ubuntu/my_project/media/;
}
}
$ ln -sf /etc/nginx/sites-available/my_project /etc/nginx/sites-enabled/
$ service nginx restart
$ service nginx status
import os, dotenv
from django.core.wsgi import get_wsgi_application
ENV_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), '.env')
dotenv.read_dotenv(ENV_DIR)
print(f"------------ ENV : {ENV_DIR}")
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.prod')
application = get_wsgi_application()