레몬베이스 온보딩 프로젝트

레몬베이스에서 실제 제품 개발에 사용하는 개발 환경 배우기

코스 전체목록

닫기

활용

정리

Gunicorn 실행 시 참고 명령어
gunicorn [project].wsgi --bind 0.0.0.0:8000 --daemon --reload
--daemon: 데몬 프로세스(백그라운드)로 구동
--reload: 소스 변경 시 재구동
참고: http://jeonghwan-kim.github.io/gunicorn-%EC%9E%A5%EA%B3%A0-%EC%96%B4%EB%93%9C%EB%AF%BC-%ED%94%84%EB%A1%9C%EB%8D%95%EC%85%98-%EC%84%9C%EB%B2%84%EC%97%90-%EA%B5%AC%EB%8F%99%ED%95%98%EA%B8%B0/
gunicorn daemon 실행 시 종료 방법
$ pkill -f gunicorn
Not Found: /static/~
WSGI에서는 Python 처리를 통해 동적(dynamic)인 컨텐츠 생성 작업을 하고, CSS,JS, 이미지 등 정적(static) 파일들은 python manage.py collectstatic 명령어를 통해 STATIC_ROOT 경로에 생성, 그리고 이 경로를 웹 서버의 접근 경로(location) 설정을 통해 웹상에서 접근할 수 있도록 하는 것.
즉, WSGI를 통해 접근할 수 있는 Django 프로젝트의 웹상 경로는 urls.py에 정의된 것들이고, 정적 파일의 웹상 접근 경로는 Nginx 등의 웹 서버가 제공해야 함.
로컬에서 setting.py에 STATIC_ROOT를 추가하고 collectstatic을 하면 wsgi 기반으로 스태틱 파일 접근 가능. 다만 상용으로 배포할 때는 다음 URL 참고할 것
https://docs.djangoproject.com/en/3.0/howto/static-files/deployment/
settings.py의 STATIC_URL은 템플릿 등에서 static 파일 경로 생성 시 사용되는 것. 즉, 이 값이 웹 서버의 스태틱 파일 location과 일치해야 함
hey is a tiny program that sends some load to a web application.
https://docs.gunicorn.org/en/latest/deploy.html
You can use Hey to check if your proxy is behaving properly.
https://github.com/rakyll/hey
Nginx 설치 on MacOS (Homebrew 사용)
https://www.sylvaindurand.org/setting-up-a-nginx-web-server-on-macos/
$ brew install nginx
$ (sudo) brew services start nginx   # 80번 포트를 쓰려면 sudo 필수
Nginx 설정 파일 수정 - 경로: /usr/local/etc/nginx/nginx.conf
세부 설정 버전 (Gunicorn 제공 가이드): https://docs.gunicorn.org/en/latest/deploy.html
단순 설정 버전: 
    https://www.sylvaindurand.org/setting-up-a-nginx-web-server-on-macos/
    https://soyoung-new-challenge.tistory.com/62 (utf-8 charset 설정 참고)
MacOS 기반 참고: http://cheng.logdown.com/posts/2015/01/29/deploy-django-nginx-gunicorn-on-mac-osx-part-2
sites-enabled 추가하여 프로젝트에 별도 nginx.conf 만들어 연결하기
http://cheng.logdown.com/posts/2015/01/29/deploy-django-nginx-gunicorn-on-mac-osx-part-2
nginx 설정에서 root, alias 차이 - root 쓰면 접근 경로를 path 뒤에 붙이고, alias는 붙이지 않음
Let me elaborate on the '/static' part. This part means that any traffic to 'your_server_ip/static' will be forwarded to '/Users/webapp/Apps/testproject/vis/static'. You might ask why doesn't it forward to '/Users/webapp/Apps/testproject/vis'?(without '/static' in the end) Because when using 'root' in the config, it will append the '/static' part after it. So be aware! You can fix this by using alias instead of root and append /static to the end of the path:
https://ohgyun.com/556 참고

댓글

댓글 본문
버전 관리
김시준
현재 버전
선택 버전
graphittie 자세히 보기