Others/Ubuntu and Linux
(Ubuntu) Django + Gunicon + Nginx 연동하기 (1)
print(blue)
2022. 4. 26. 16:49
gunicorn은
WSGI(Web Server Gateway Interface) 서버
WSGI란 python으로 작성된 웹 어플리케이션과 python으로 작성된 서버 사이의 약속된 인터페이스 또는 규칙
개발이 아니라 서버에 필요한 도구라 로컬 환경에 설치할 필요 없당
그래서
1. 서버 환경에 gunicon 설치 !
(django_site) ubuntu@ip-172-31-11-144:~/django_site$ pip install gunicorn
Collecting gunicorn
Downloading gunicorn-20.1.0-py3-none-any.whl (79 kB)
|████████████████████████████████| 79 kB 7.7 MB/s
Requirement already satisfied: setuptools>=3.0 in /home/ubuntu/anaconda3/envs/django_site/lib/python3.10/site-packages (from gunicorn) (61.2.0)
Installing collected packages: gunicorn
Successfully installed gunicorn-20.1.0
2. 정상적으로 실행되는지 테스트 해보깅
> gunicorn --bind 0.0.0.0:8000 프로젝트이름.wsgi:application
난 점프 투 장고 보면서 따라함
(django_site) ubuntu@ip-172-31-11-144:~/django_site$ gunicorn --bind 0:8000 config.wsgi:application
[2022-04-26 08:47:16 +0000] [121042] [INFO] Starting gunicorn 20.1.0
[2022-04-26 08:47:16 +0000] [121042] [INFO] Listening at: http://0.0.0.0:8000 (121042)
[2022-04-26 08:47:16 +0000] [121042] [INFO] Using worker: sync
[2022-04-26 08:47:16 +0000] [121043] [INFO] Booting worker with pid: 121043
서비스 설정은 나중에 (서버 꺼질 일은 별룽 없으니까 실행된 거 봤으니까 나중에 설정만져주깅)
3. 시스템 데몬 재시작
(django_site) ubuntu@ip-172-31-11-144:~$ sudo systemctl daemon-reload
서비스를 새로 등록하거나 수정할 경우 데몬 리로드하기
4. 실행 상태 확인하기
(django_site) ubuntu@ip-172-31-11-144:~/django_site$ cd /etc/systemd/system
(django_site) ubuntu@ip-172-31-11-144:/etc/systemd/system$ sudo systemctl status mysite.service
● mysite.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/mysite.service; enabled; vendor preset: enabled)
Active: failed (Result: resources) since Wed 2022-04-27 09:11:11 UTC; 16min ago
Apr 27 09:11:11 ip-172-31-11-144 systemd[1]: Started gunicorn daemon.
Apr 27 09:11:11 ip-172-31-11-144 systemd[125656]: mysite.service: Changing to the requested working directory failed: N>
Apr 27 09:11:11 ip-172-31-11-144 systemd[125656]: mysite.service: Failed at step CHDIR spawning /home/ubuntu/venvs/djan>
Apr 27 09:11:11 ip-172-31-11-144 systemd[1]: mysite.service: Main process exited, code=exited, status=200/CHDIR
Apr 27 09:11:11 ip-172-31-11-144 systemd[1]: mysite.service: Failed with result 'exit-code'.
Apr 27 09:26:44 ip-172-31-11-144 systemd[1]: mysite.service: Failed to load environment files: No such file or directory
Apr 27 09:26:44 ip-172-31-11-144 systemd[1]: mysite.service: Failed to run 'start' task: No such file or directory
Apr 27 09:26:44 ip-172-31-11-144 systemd[1]: mysite.service: Failed with result 'resources'.
Apr 27 09:26:44 ip-172-31-11-144 systemd[1]: Failed to start gunicorn daemon.
lines 1-13/13 (END)client_loop: send disconnect: Broken pipe
vi /etc/nginx/sites-enabled/config
출처: https://nalara12200.tistory.com/164 [IT, 정보보안 자료실]