Skip to content

Latest commit

 

History

History
141 lines (116 loc) · 3.73 KB

배포.md

File metadata and controls

141 lines (116 loc) · 3.73 KB
  1. uwsgi 설치
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install build-essential libssl-dev libffi-dev python3-dev lib32ncurses5-dev libmysqlclient-dev
sudo apt-get install uwsgi-plugin-python
git clone ...
sudo apt-get install python3-pip uwsgi
sudo pip3 install -r requirements.txt
# env 설정
# uwsgi 테스트
uwsgi --http :8000 --module mysite3.wsgi
uwsgi --http-socket :8000 --module mysite3.wsgi

uwsgi --ini uwsgi.ini

  • 실행 $ uwsgi uwsgi.ini
  • uWSGI 로그확인 $ vi mysite3.uwsgi.log
  • uWSGI 중지 $ uwsgi --stop mysite3.uwsgi.pid
# mysite_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir           = /home/ubuntu/sgd/mysite3
# Django's wsgi file
module          = mysite3.wsgi:application
# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 10
# the socket (use the full path to be safe
socket          = /home/ubuntu/django.sock
# ... with appropriate permissions - may be needed
chmod-socket    = 666
# clear environment on exit
vacuum          = true
  1. Uwsgi systemd 등록

/etc/systemd/system/django.service

# /etc/systemd/system/django.service
[Unit]
Description=uWSGI
After=syslog.target

[Service]
ExecStart=/home/ubuntu/.local/bin/uwsgi --ini /home/ubuntu/sgd/mysite3/uwsgi.ini # ini의 경로로 입력
User=ubuntu
Group=www-data
# Requires systemd version 211 or newer
RuntimeDirectory=uwsgi
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl start django.service
  1. nginx 설치
sudo apt-get install nginx

etc/nginx/sites-available/default

upstream django {
    server unix:///home/ubuntu/django.sock;
    #server 127.0.0.1:8000;
}

server {
    listen                   80; # nginx가 listen할 포트
    server_name              127.0.0.1 #서버 도메인이나 아이피 입력
    client_max_body_size     10M;
    access_log               /var/log/mysite.access.log; # 성공 로그를 기록할 파일
    error_log                /var/log/mysite.error.log; # 에러 로그를 기록할 파일

    # -------------
    # Handle Django
    # -------------

    location / {
        include /etc/nginx/uwsgi_params;
    	uwsgi_pass django;
        # 외부에서 특정 포트로 Nginx를 통해 http 요청을 받았을 때 요청을 uWSGI를 통해 Django로 넘김
        #proxy_pass       http://localhost:8000; # uWSGI가 nginx 요청을 받을 주소와 포트
        #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;
    }

    # ------------------
    # serve static files
    # ------------------


    # here we assume the STATIC_ROOT inside your django project is
    # set to /static/
    location /static/ {
    	# /static/ 으로 들어 올 때 경로 설정.
        alias   /home/ubuntu/sgd/mysite3/staticfiles/; # django project settings.py에 설정되어있는 STATIC_ROOT 주소
    }


    location /media/ {
        # /static/ 으로 들어 올 때 경로 설정.
        alias   /home/ubuntu/sgd/mysite3/mediafiles/; # django project settings.py에 설정되어있는 STATIC_ROOT 주소
    }

    # location /static/ {
    #     alias           https://mysite-sgd.s3.ap-northeast-2.amazonaws.com/static/;
    # }

    # location /media/ {
    #     alias           https://mysite-sgd.s3.ap-northeast-2.amazonaws.com//media/;
    # }
}