django restAPI, aws 연결 차근차근 해보기(3)
이제 계속 터미널에서 서버를 킨 상태로 둘 수 없으니 uwsgi를 사용해 보기
계속 서버 연결해 주도록!
1. uwsgi 설치
pip install uwsgi
2. uwsgi 파일 작성
vi uwsgi.ini
위 명령어를 통해 편집기로 이동 후
[uwsgi]
chdir=/home/ubuntu/{프로젝트 폴더}
module={프로젝트 내 파일이름}.wsgi:application
master=True
pidfile=/tmp/project-master.pid
vacuum=True
max-requests=5000
daemonize=/home/ubuntu/{프로젝트 폴더}/django.log
home=/home/ubuntu/{프로젝트 폴더}/venv
virtualenv=/home/ubuntu/{프로젝트 폴더}/venv
socket=/home/ubuntu/{프로젝트 폴더}/uwsgi.sock
chmod-socket=666
// 예시
// [uwsgi]
// chdir=/home/ubuntu/testBugi/testBugi
// module=testBugi.wsgi:application
// master=True
// pidfile=/tmp/project-master.pid
// vacuum=True
// max-requests=5000
// daemonize=/home/ubuntu/testBugi/django.log
// home=/home/ubuntu/testBugi/venv
// virtualenv=/home/ubuntu/testBugi/venv
// socket=/home/ubuntu/testBugi/uwsgi.sock
// chmod-socket=666
빈 파일에 이걸 입력해 준다 (:wq로 저장 후 빠져나가기)
폴더 구조를 좀 이상하게 만들어서 경로 지정이 헷갈릴 수도..
uwsgi --ini uwsgi.ini
// [uWSGI] getting INI configuration from uwsgi.ini
그리고 이 명령어를 통해 설정을 반영
3. nginx 설치
sudo apt-get install nginx
설치 후 파일을 수정해줘야 함
sudo vi /etc/nginx/nginx.conf
user ubuntu; // <- 여기 변경
worker_processes auto;
pid /run/nginx.pid;
error_log /var/log/nginx/error.log;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
upstream django { // <- 이 구문 작성
server unix:/home/ubuntu/testBugi/uwsgi.sock;
}
##
# Basic Settings
##
하나 더 수정
sudo vi /etc/nginx/sites-enabled/default
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404; // <- 주석
include /etc/nginx/uwsgi_params; // <- 작성
uwsgi_pass django; // <- 작성
}
location /static/ { // <- 작성
alias /home/ubuntu/testBugi/testBugi/static/;
}
# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
4. 실행
sudo service nginx restart
이러면 되는데!
...
이상한 오류....
그래서 삽질해 봤더니
testBugi 디렉터리 안에 venv가 없고 그 밖에 있던 것!!
가상환경 비활성화 해준 뒤
cd ~/testBugi
rm -rf venv
virtualenv -p python3 venv
source venv/bin/activate
바로 옮겨주고 다시 위 과정부터 차례대로..!
다음부터는 가상환경 위치도 프로젝트 안에 제대로 넣자!
그럼 이렇게 뜨는데
아까 static 파일을 수집하는 명령어를 입력!
python manage.py collectstatic
// 195 static files copied to '/home/ubuntu/testBugi/testBugi/static'.
하고 다시 restart 하면!
휴~ 된다
파일 구조 잘!
경로 설정 잘!
다음은 sql연결, 데이터 반영을 해보께여
https://nerogarret.tistory.com/46?category=800142
Django 서비스 AWS로 배포하기 - [2] github과 프로젝트 업로드
Django 서비스 AWS로 배포하기 - [1] 프로젝트 준비와 AWS 서버 대여 지난 번 포스팅에서는 AWS에서 EC2 컴퓨터를 대여하고 기본적으로 세팅해 보았습니다. 이번 포스팅에서는 git과 github을 통해 프로젝
nerogarret.tistory.com
https://www.youtube.com/watch?v=oGQ1HteFYnQ