ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Ubuntu 18.04에서 Gunicorn 설치
    About AWS 2019. 6. 29. 16:36

    사용하는 이유

    • Django 서비스를 AWS에서 이용하기 위해서

    준비물

    • python

    • pip

    설치

    1. cd ~/프로젝트 폴더로 이동

     

    2.

    pipenv --python 3.7

    로 Python 버전에 맞는 가상환경 설정

     

    3.

    pipenv install gunicorn django django-model-utils

    로 가상환경에 gunicorn, django, django-model-utils 설치

     

    4.

    cd /var 로 이동

     

    5.

    sudo chown -R ubuntu:www-data www

    으로 www 폴더의 소유권 변경

     

    6.

    sudo vi /etc/systemd/system/gunicorn.service에 아래와 같이 입력

    [Unit]
    
    Description = gunicorn 프로젝트명  daemon
    
    After = network.target
    
    [Service]
    
    User = ubuntu
    
    Group = www-data
    
    WorkingDirectory = /home/ubuntu/프로젝트 폴더
    
    ExecStart = /home/ubuntu/프로젝트 가상환경 주소/bin/gunicorn \
    
    --access-logfile - \
    
    --workers 3 \
    
    --bind unix:/var/www/프로젝트명.sock \
    
    Whendy.wsgi:application
    
    [Install]
    
    WantedBy=multi-user.target

     

    7.

    sudo systemctl start gunicorn.service
    
    sudo systemctl enable gunicorn.service

    현재 상태에서, /var/www에 프로젝트명.sock 파일이 생성되어야 함

    sudo systemctl status gunicorn.service 화면이 아래와 같아야 함

     

    8. sudo vi /etc/caddy/Caddyfile 파일을 다음과 같이 변경

    프로젝트 URL {
    
        request_id
    
        header / X-Request-Id {request_id}
    
        log / stdout “{remote} - {request_id} [{when}] \ “{method} {url} {proto}\” {status} {size} \”{>Referer}\”\”{>User-Agent}\” ”
    
    
    
        root /var/www/프로젝트명
    
        proxy / unix:/var/www/프로젝트명.sock{
    
        except /media /static
    
        header_upstream Host {host}
    
        header_upstream X-Real-IP {remote}
    
        header_upstream X-Forwarded-For {remote}
    
        header_upstream X-Forwarded-Proto {scheme}
    
        header_upstream X-Request-Id {request_id}
    
      }
    
    gzip
    
    }

     

    'About AWS' 카테고리의 다른 글

    Ubuntu 18.04에서 python 3.7, pip 설치  (0) 2019.06.27
    AWS Ubuntu 18.04 Caddy 세팅  (0) 2019.06.27
    AWS Ubuntu 세팅  (0) 2019.06.27

    댓글

Designed by Tistory.