Aws ec2를 이용해 Django 서버 배포하기에 앞서
- 네로의 다락방님의 글을 보며 진행하였습니다. 네로의 다락방님이 간결하고 알기 쉽게 설명해 주셔서 무사히 배포할 수 있었습니다. 감사합니다.
- 해당 글은 저의 프로젝트 배포를 진행하며 생긴 문제점과 해결방안 등 다시 정리해가며 글을 새롭게 작성됩니다.
- 진행하는 OS는 mac 환경입니다.
- window 환경이라면 mobaxterm 사용을 추천드립니다. (따로 가이드 작성 예정)
- 리눅스 명령어를 따로 설명하지 않습니다.
- COVID-19-REPORT 프로젝트를 실제 사용해 보기 위하여 배포를 진행합니다.
- 현재 글은 배포 방법만 정리하였으며 설명을 추가중에 있습니다.
uwsgi 설치
pip3 install uwsgi
홈으로 이동해 uwsgi를 설치합니다.
uwsgi의 설치 이유와 uwsgi란?
- 추가예정
혹시 설치하다 해당 에러가 발생한다면
Failed building wheel for uwsgi
Running setup.py clean for uwsgi
Failed to build uwsgi
Installing collected packages: uwsgi
Running setup.py install for uwsgi ... error
Complete output from command /home/ubuntu/myvenv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-960f4exl/uwsgi/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-yd21s993-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/ubuntu/myvenv/include/site/python3.6/uwsgi:
/usr/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'descriptions'
warnings.warn(msg)
running install
using profile: buildconf/default.ini
detected include path: ['/usr/include', '/usr/local/include']
Traceback (most recent call last):
File "/tmp/pip-build-960f4exl/uwsgi/uwsgiconfig.py", line 747, in __init__
gcc_version_components = gcc_version.split('.')
AttributeError: 'NoneType' object has no attribute 'split'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-960f4exl/uwsgi/setup.py", line 140, in <module>
'Programming Language :: Python :: 3.8',
File "/home/ubuntu/myvenv/lib/python3.6/site-packages/setuptools/__init__.py", line 129, in setup
return distutils.core.setup(**attrs)
File "/usr/lib/python3.6/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/lib/python3.6/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/tmp/pip-build-960f4exl/uwsgi/setup.py", line 77, in run
conf = uc.uConf(get_profile())
File "/tmp/pip-build-960f4exl/uwsgi/uwsgiconfig.py", line 755, in __init__
raise Exception("you need a C compiler to build uWSGI")
Exception: you need a C compiler to build uWSGI
----------------------------------------
Command "/home/ubuntu/myvenv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-960f4exl/uwsgi/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-yd21s993-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/ubuntu/myvenv/include/site/python3.6/uwsgi" failed with error code 1 in /tmp/pip-build-960f4exl/uwsgi/
해결 방법 : https://integer-ji.tistory.com/294
uwsgi를 이용해 django와 연결
uwsgi --http :"포트번호" --home "가상환경 경로" --chdir "장고프로젝트폴더 경로" -w "wsgi 모듈이 있는 폴더"
uwsgi --http :8080 --chdir /srv/covid-19-report/ --wsgi-file project/wsgi.py
*.wsgi 파일은 자신이 생성한 project 폴더 안에 있습니다.
이제는 runserver가 아니라 위의 uwsgi를 이용하면 서버가 실행됩니다.
자신의 퍼블릭 DNS(IPv4):8080
http://ec2-15-164-100-29.ap-northeast-2.compute.amazonaws.com:8080/
접속하게 되면
uwsgi로 서버 실행시키기
끝!
--- no python application found, check your startup logs for errors ---
[pid: 31839|app: -1|req: -1/1] 124.48.218.247 () {38 vars in 828 bytes} [Mon Aug 31 15:17:35 2020] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
만약 해당 에러가 나온다면..
해당 에러는 uwsgi --http :8080 --home /home/ubuntu/myvenv/ --chdir /srv/covid-19-report/ -w project.wsgi
에서 wsgi가 있는 위치를 잘못 입력해서 그런것입니다.
uwsgi --http :8080 --chdir /srv/covid-19-report/ --wsgi-file project/wsgi.py
끝!
'코딩공부 > Server' 카테고리의 다른 글
Aws ec2를 이용해 Django 서버 배포하기 - nginx와 uwsgi 연결 (0) | 2020.09.10 |
---|---|
Aws ec2를 이용해 Django 서버 배포하기 - ec2 계정 만들기 (0) | 2020.09.08 |
Aws ec2를 이용해 Django 서버 배포하기 - ec2 인스턴스 가상환경, runserver 실행하기 (0) | 2020.09.07 |
Aws ec2를 이용해 Django 서버 배포하기 - ec2서버에 secrets.json 파일 전송하기 (1) | 2020.09.07 |
Aws ec2를 이용해 Django 서버 배포하기 - ec2서버와 git 연동하기 (0) | 2020.09.07 |