사용자 도구

사이트 도구


python:django:ubuntu

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판이전 판
다음 판
이전 판
python:django:ubuntu [2025/04/17 13:51] – [Apache mode_wsgi + Django 연동] taekgupython:django:ubuntu [2025/04/20 00:51] (현재) – [Apache2 설정] taekgu
줄 2: 줄 2:
  
 가상환경 가상환경
 +python3-venv
 <code bash> <code bash>
-python3 -m venv maroenv+python3 -m venv marovenv
 </code> </code>
 +[[linux:django:ubuntu:uwsgi|삽질]]
 ===== uWSGI ===== ===== uWSGI =====
 [[http://uwsgi-docs.readthedocs.io/en/latest/|공식페이지]] [[http://uwsgi-docs.readthedocs.io/en/latest/|공식페이지]]
줄 19: 줄 21:
   * XSLT스타일을 적용하는 등의 콘텐츠 처리 수행   * XSLT스타일을 적용하는 등의 콘텐츠 처리 수행
 ==== uWSGI 설치 ==== ==== uWSGI 설치 ====
 +build-essential gcc
 <code bash> <code bash>
 apt install uwsgi apt install uwsgi
 +# uwsgi plugins - 잘은 모르겠으나 필요함.ㅠ.ㅠ
 +sudo apt-get install uwsgi-plugin-python3
 </code> </code>
  
줄 28: 줄 33:
  
 /etc/init 디렉토리에 있는 선언적 구성 파일을 기반으로 실행한다 /etc/init 디렉토리에 있는 선언적 구성 파일을 기반으로 실행한다
-=== simple script (/etc/init/uwsgi.conf) ===+=== ini파일은 /etc/uwsgi/apps-enabled === 
 + 
 +<code conf maro_uwsgi.ini> 
 +[uwsgi
 +uid=akfd 
 +base=/home/akfd/pro 
 + 
 +# the virtualenv (full path) 
 +home=/home/akfd/venb 
 +chdir=/home/akfd/pro/akfdro 
 + 
 +module=conf.wsgi:application 
 +env=DJANGO_SETTINGS_MODULE=conf.settings.develop 
 + 
 +autoload=true 
 +# process-related settings 
 +# uWSGI 프로세스를 master로 돌아가게 해줍니다. 
 +master=true 
 + 
 +# maximum number of worker processes 
 +processes=5 
 + 
 +max-requests=5000 
 +daemonize=/var/log/pro/uwsgi.log 
 + 
 +# HTTP-PORT 
 +http-socket=:8000 
 +# UNIX socket 파일의 위치입니다. socket file의 위치를 잡아줘도 되며 localhost와 port를 명시해줘도 됩니다. 
 +socket=/var/log/_uwsgi.sock 
 +# UNIX socket 소유자 
 +chown-socket=%(uid):www-data 
 +# UNIX socket에 대한 권한 설정입니다. 666을 해야 실행이 가능합니다. 
 +chmod-socket=660 
 +# uWSGI를 통해서 생성된 파일들은 삭제하는 옵션입니다. 
 +vacuum=true 
 + 
 +# thread 사용을 앱(uWSGI) 내에서 가능하게 해줍니다. 
 +enable-threads = true 
 +# 단일한 python interpreter를 사용하게 하는 옵션입니다. 
 +single-interpreter = true 
 +# master말고 각각의 worker에(master에서 spawn한 자식들) 앱을 로드하는 설정입니다. 
 +lazy-apps true
  
-<code bash> 
-# simple uWSGI script 
-description "uwsgi tiny instance" 
-start on runlevel [2345] 
-stop on runlevel [06] 
-respawn 
-exec uwsgi --master --processes 4 --die-on-term --socket :3031 --wsgi-file /var/www/myapp.wsgi 
 </code> </code>
 ==== uWSGI 설정 ==== ==== uWSGI 설정 ====
줄 89: 줄 128:
 </code> </code>
  
-==== Python + Apache mod_wsgi 연동 ====+===== Apache2 설정 ===== 
 +Apache에서는 proxy_uwsgi를 이용하여 접속한다.
  
- +<code conf zaro.conf>
-=== Apache mod_wsgi란? === +
- +
-mod_wsgi의 목적은 Python WSGI 인터페이스를 지원하는 Python 응용 프로그램을 호스팅 할 수 있는 간 +
-단한 ApacheModule을 구현하는 것이다. 이 모듈은 웹 호스팅 서비스에서 실행되는 고성능 운영 사이트뿐 +
-만 아니라 고성능 프로덕션 웹 사이트 호스팅에도 사용하기에 적합하다. +
-지원 가능한 웹프레임워크 및 어플리케이션 +
-  * CherryPy +
-  * Django +
-  * Pylons +
-  * TurboGears +
-  * Pyramid +
-  * web.py +
-  * Werkzeug +
-  * Web2Py and Zope. +
- +
-=== 아파치 설치 === +
-<code bash> +
-# apt-get install apache2 +
-</code> +
- +
-=== 아파치 wsgi 설정 === +
- +
-<code conf /etc/apache2/conf-available/wsgi.conf+
-WSGIScriptAlias /test_wsgi /var/www/html/test_wsgi.py +
-</code> +
- +
-=== 아파치 wsgi 설정 === +
- +
-$ a2enconf wsgi +
-$ systemctl restart apache2 +
- +
-=== test_wsgi.py 생성 === +
- +
-<code pyton /var/www/html/test_wsgi.py>+
 # create new # create new
-def application(environ,start_response): +ProxyPass /nakkko unix:/var/log/_uwsgi.sock|uwsgi://localhost:8000/nakkko
-status = '200 OK' +
-html = '<html>\n'+
-'<body>\n'+
-'<div style="width100%; font-size: 40px; font-weight: bold; text-align: center;">\n'+
-'mod_wsgi Test Page\n'+
-'</div>\n'+
-'</body>\n'+
-'</html>\n' +
-response_header = [('Content-type','text/html')] +
-start_response(status,response_header) +
-return [html] +
-</code>+
  
-=== test_wsgi 페이지 확인 ===+Alias /grrr /var/ggggg/grrr 
 +<Directory "/var/ggggg/grrr"> 
 + Require all granted 
 +</Directory>
  
-웹브라우저에서 http://localhost/test_wsgi 접속하여 확인한다. +Alias /static /var/ggggg/static 
- +<Directory "/var/ggggg/static"> 
-==== Apache mode_wsgi + Django 연동 ==== + Require all granted 
- +</Directory>
-=== 사전 환경 구축 === +
- +
-  * virtualenv 설치 +
-  * django 설치 +
-  * Apache2 설치 +
-  * mod_wsgi 설치 +
- +
-=== Django란? === +
- +
-Django는 안전하고 유지 관리 가능한 웹 사이트를 신속하게 개발할 수 있는 고차원적인 Python 기반 웹 +
-프레임워크이다. 경험이 풍부한 개발자들에 의해 구축된 장고(Django)는 웹 개발의 번거로움을 해소할 수 +
-있도록 하기 위해 고안되었다. 자유롭고 개방적이며 활발한 커뮤니티를 보유하고 있으며, 우수한 문서 및 +
-유료 지원을 위한 다양한 옵션을 갖추고 있다. +
- +
-=== virtualenv 설치 === +
- +
-가상 작업환경인 virtualenv를 설치한다. +
-<code bash> +
-root@www:~# apt-get -y install python-virtualenv+
 </code> </code>
- 
-=== virtualenv 설정 === 
-<code bash> 
-ubuntu@www:~$ virtualenv venv # virtualenv 생성 
-ubuntu@www:~$ cd ~/venv 
-ubuntu@www:~/venv$ source bin/activate 
-(venv)ubuntu@www:~/venv$ pip install -U pip 
-(venv)ubuntu@www:~/venv$ pip install django #django 설치 
-</code> 
- 
-=== 테스트 프로젝트 생성 === 
-<code bash> 
-Ubuntu@www:~$ cd ~/venv 
-Ubuntu@www:~/venv$ source bin/activate 
-# create “testproject” 
-(venv)ubuntu@www:~/venv$ django-admin startproject testproject 
-(venv)ubuntu@www:~/venv$ cd testproject 
-</code> 
- 
-=== 데이터베이스 설정(SQLite) === 
-<code bash> 
-# configure database (default is SQLite) 
-(venv)ubuntu@www:~/venv/testproject$ python manage.py migrate 
-# create admin user 
-(venv)ubuntu@www:~/venv/testproject$ python manage.py createsuperuser 
-</code> 
- 
-=== 서버 실행 === 
-<code bash> 
-# start server 
-venv)ubuntu@www:~/venv/testproject$ python manage.py runserver 0.0.0.0:8000 
-</code> 
- 
-=== Apache mode_wsgi + Django 연동 === 
- 
-views.py 작성 
-<code python testapp/views.py> 
-# -*- coding: utf-8 -*- 
-from __future__ import unicode_literals 
- 
-from django.shortcuts import render 
- 
-from django.http import HttpResponse 
-def main(request): 
-    html = '<html>\n' \ 
-           '<body>\n' \ 
-           '<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">\n' \ 
-           'Django Test Page\n' \ 
-           '</div>\n' \ 
-           '</body>\n' \ 
-           '</html>\n' 
-    return HttpRestponse(html) 
- 
-# Create your views here. 
-</code> 
-</code> 
- 
python/django/ubuntu.1744897889.txt.gz · 마지막으로 수정됨: 2025/04/17 13:51 저자 taekgu