-
<Django>[uwsgi + nginx 설정]Flower in my dev/Django 2016. 10. 23. 19:14
[uwsgi + nginx 설정]
1. 프로젝트 생성
- django-admin.py startproject [프로젝트명]
2. uwsgi 설치
- sudo pip3 install uwsgi
3. 프로젝트를 uwsgi로 실행
- uwsgi --http :8000 --module flower.wsgi
4. 결과 확인
5. nginx 설치
- sudo apt-get install nginx
6. nginx 설정
- vi flower_nginx.conf
12345678910111213141516171819202122232425262728293031323334# flower_nginx.conf# the upstream component nginx needs to connect toupstream django {# server unix:///opt/webapp/flower/flower.sock; # for a file socketserver 192.168.0.200:8080; # for a web port socket (we'll use this first)}# configuration of the serverserver {# the port your site will be served onlisten 8000;# the domain name it will serve forserver_name www.flower.com; # substitute your machine's IP address or FQDNcharset utf-8;# max upload sizeclient_max_body_size 75M; # adjust to taste# Django medialocation /media {alias /opt/webapp/flower/media; # your Django project's media files - amend as required}location /static {alias /opt/webapp/flower/static; # your Django project's static files - amend as required}# Finally, send all non-media requests to the Django server.location / {uwsgi_pass django;include /opt/webapp/flower/uwsgi_params; # the uwsgi_params file you installed}}cs 7. nginx 설정 파일 링크 걸기
- cd /etc/nginx/sites-enabled/
- sudo ln -s /opt/webapp/flower/flower_nginx.conf ./
- default 링크는 삭제
8. static 설정 추가
- vi flower/settings.py
- STATIC_ROOT = os.path.join(BASE_DIR, "static/") <--추가
- python3 manage.py collectstatic
9. nginx와 uwsgi 사이에 socket 추가
- vi uwsgi_params
- nginx 재시작 (nginx는 설정이 바뀔때면 재시작)12345678910111213141516uwsgi_param QUERY_STRING $query_string;uwsgi_param REQUEST_METHOD $request_method;uwsgi_param CONTENT_TYPE $content_type;uwsgi_param CONTENT_LENGTH $content_length;uwsgi_param REQUEST_URI $request_uri;uwsgi_param PATH_INFO $document_uri;uwsgi_param DOCUMENT_ROOT $document_root;uwsgi_param SERVER_PROTOCOL $server_protocol;uwsgi_param REQUEST_SCHEME $scheme;uwsgi_param HTTPS $https if_not_empty;uwsgi_param REMOTE_ADDR $remote_addr;uwsgi_param REMOTE_PORT $remote_port;uwsgi_param SERVER_PORT $server_port;uwsgi_param SERVER_NAME $server_name;cs - sudo /etc/init.d/nginx restart
- uwsgi --socket /home/pi/flower/flower.sock --module flower.wsgi --chmod-socket=666
10. 디렉토리 확인
11. uwsgi 설정 파일 만들기
- vi flower_uwsgi.ini
123456789101112131415161718# flower_uwsgi.ini[uwsgi]# Django-related settings# the base directory (full path)chdir = /opt/webapp/flower/# Django's wsgi filemodule = flower.wsgimaster = true# maximum number of worker processesprocesses = 5# the socket (use the full path to be safesocket = /opt/webapp/flower/flower.sock# ... with appropriate permissions - may be neededchmod-socket = 666# clear environment on exitvacuum = truecs 12. uwsgi 설정 파일로 실행
- uwsgi --ini flower_uwsgi.ini
13. Emperor 모드로 실행
- Emperor 모드 : uwsgi 설정의 Watch Dog 기능
- sudo mkdir /etc/uwsgi
- sudo mkdir /etc/uwsgi/vassals
- mkdir -p : 상위경로까지 한번에 생성
- uwsgi --emperor /etc/uwsgi/vassals --uid www-data --gid www-data
14. 마지막 디렉토리 확인
'Flower in my dev > Django' 카테고리의 다른 글
<DJANGO>[Hello World] (0) 2017.03.05 <DJANGO>[pyenv] 사용하기 (0) 2017.03.05 <DJANGO>[django+postgresql 우분투 개발 환경 만들기] (0) 2016.05.11 <DJANGO>['ascii' codec can't encode characters in position 0-2: ordinal not in range(128)] (0) 2016.01.25 <DJANGO>[django 설치] (0) 2015.11.18