티스토리 뷰
[WEB & WAS] Apache & Django Python 3.x
WEB & DB Server 구성
WEB Server에는 Apache & Django, DB Server에는 MariaDB로 구성하여 WEB Server와 DB Server를 나눈 형태로 구성합니다.
이번 포스팅에서는 Apache & Django를 Python 3.x환경에서 구성하는 포스팅을 진행합니다.
Python3.x 설치
[root@web-test-02 ~]# yum install -y https://centos7.iuscommunity.org/ius-release.rpm [root@web-test-02 ~]# yum install -y python36u python36u-libs python36u-devel python36u-pip |
Apache 및 mod_wsgi 모듈 설치
Apache 설치
[root@web-test-02 ~]# yum -y install httpd |
mod_wsgi 모듈 설치, mod_wsgi는 Apache와 Django를 연결해주는 모듈입니다.
[root@web-test-02 ~]# yum install -y python36u-mod_wsgi |
Django 설치
[root@web-test-02 ~]# pip3.6 install --upgrade pip [root@web-test-02 ~]# pip3.6 install django |
Django 프로젝트 생성
Django 프로젝트를 생성할 디렉토리로 이동 및 Django 프로젝트 생성
[root@web-test-02 ~]# cd /opt [root@web-test-02 opt]# django-admin startproject web01 |
Apache 설정
vhost.conf 파일 생성 및 아래 내용 작성
[root@web-test-02 opt]# vi /etc/httpd/conf.d/vhost.conf <VirtualHost *:80> ServerName localhost Alias /static/admin /usr/lib64/python3.6/site-packages/django/contrib/admin/static/admin WSGIScriptAlias / /opt/web01/web01/wsgi.py WSGIDaemonProcess web01 python-path=/opt/web01/web01 <Directory /opt/web01/web01> <Files wsgi.py> AllowOverride none Require all granted </Files> </Directory> </VirtualHost> |
wsgi.py 수정
[root@web-test-02 opt]# vi /opt/web01/web01/wsgi.py """ WSGI config for web01 project. It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ """ import os import sys from django.core.wsgi import get_wsgi_application path = '/opt/web01' if path not in sys.path: sys.path.append(path) os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'web01.settings') application = get_wsgi_application() |
setting.py 수정 - ALLOWED_HOSTS의 값을 '*'로 수정
[root@web-test-02 opt]# vi /opt/web01/web01/settings.py import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = '^ficswq#s7h71fvi86oe=15sy5csk6hi%eh6ti6g3dj%j@vnmx' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = ['*'] # Application definition |
httpd.conf 수정
[root@web-test-02 opt]# vi /etc/httpd/conf/httpd.conf # Deny access to the entirety of your server's filesystem. You must # explicitly permit access to web content directories in other # <Directory> blocks below. # <Directory /> AllowOverride none Require all granted </Directory> # # Note that from this point forward you must specifically allow # particular features to be enabled - so if something's not working as # you might expect, make sure that you have specifically enabled it # below. |
Apache 재시작
[root@web-test-02 opt]# systemctl restart httpd |
Django 연동 확인
브라우저에서 Web 접속하여 확인
'[Web] > WEB & WAS' 카테고리의 다른 글
[WEB & WAS] Django & Nginx & uWSGI - Python env (0) | 2019.04.24 |
---|---|
[WEB & WAS] Apache & Django & MariaDB (0) | 2018.12.17 |
[WEB & WAS] Apache & Django & Python 2.x (0) | 2018.11.02 |
[WEB & WAS] Web Server 구축하기(Apache & PHP & MariaDB) (0) | 2018.07.09 |
[Web Server] Windwos - Apache &Tomcat 연동 (0) | 2016.05.21 |
Comments
최근에 올라온 글