centos + anaconda + django + uwsgi + nginx 배치
# info
# centos 7
# anaconda 2019.03
# python 3.6
# django 2.1
# uwsgi 2.0.18
# nginx 1.16.1
1. 기본 패키지 설치
# yum groupinstall "Development tools"
# yum install zlib-devel bzip2-devel pcre-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel
# yum install pcre pcre-devel pcre-static
# yum install python3-devel
# yum install uwsgi-plugin-python36*
2. 프로젝트 디 렉 터 리
cjc
# useradd cjc
# passwd cjc
Downloads
, Project
$ mkdir ~/Downloads/
$ mkdir ~/Project/
wget
# yum install wget
wget
시 Anaconda
다운로드 ~/Downloads/
$ wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2019.03-Linux-x86_64.sh
Anaconda
$ bash ~/Downloads/Anaconda3-2019.03-Linux-x86_64.sh
$ source ~/.bashrc
conda
가상 환경 만 들 기 My_Django
, 지정 python
버 전 3.6
$ conda create -n My_Django python==3.6
My_Django
$ conda activate My_Django
django
$ pip install django==2.1
~/Project/
디 렉 터 리 에서 항목 생 성 Myweb
$ django-admin startproject Myweb
Myapp
$ python manage.py startapp Myapp
Myweb/Myweb/settings.py
ALLOWED_HOSTS = ['*',]
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'Myapp',]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates'),],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
LANGUAGE_CODE = 'zh-hans'
TIME_ZONE = 'Asia/Shanghai'
STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
STATIC_ROOT = '/home/cjc/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
Bootstrap
다운로드 후 파일 압축 풀기 Myweb/static/
https://v3.bootcss.com/getting-started/#download Myweb/templates/Myapp/index.html
Myweb/Myapp/views.py
def index(request):
return render(request, 'Myapp/index.html')
Myweb/Myweb/urls.py
from django.contrib import adminfrom
from django.urls import pathfrom
from Myapp.views import index as Myapp_index
urlpatterns = [
path('admin/', admin.site.urls),
path('', Myapp_index),]
7. uwsgi
uwsgi
$ pip install uwsgi
~/Project/Myweb/
파일 만 들 기 uwsgi.ini
How to use Django with uWSGI [uwsgi]
socket = :8000
chdir = /home/cjc/Project/Myweb
module = Myweb.wsgi
master = true
processes = 5
threads = 5
vacuum = true
pidfile = /tmp/Myweb-master.pid
daemonize = /var/log/uwsgi/Myweb.log
socket
소켓 연결 chdir
프로젝트 경 로 를 사용 합 니 다. 즉, my site 패키지 가 포 함 된 디 렉 터 리 module
가 사용 할 wgi 모듈 master
이 주 스 레 드 processes
시작 프로 세 스 수 threads
시작 스 레 드 수 vacuum
서버 가 물 러 날 때 pid pidfile
가 지정 한 시작 시의 pid daemonize
uwsgi 로그 경로 uwsgi
$ uwsgi --ini uwsgi.ini
#
$ uwsgi --reload /tmp/Myweb-master.pid
#
$ uwsgi --stop /tmp/Myweb-master.pid
nginx
# yum install nginx
nginx
, /etc/nginx/nginx.conf
user cjc;
server {
listen 80;
server_name 127.0.0.1;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8000;
uwsgi_param UWSGI_SCRIPT Myweb.wsgi;
uwsgi_param UWSGI_CHDIR /home/cjc/Project/Myweb;
client_max_body_size 35m;
}
location /static {
alias /home/cjc/static;
}
}
nginx
# systemctl start nginx
#
# systemctl restart nginx
#
# systemctl stop nginx
uwsgi
설치 필요 gcc
, pcre
# log
!!! no internal routing support, rebuild with pcre support !!!
nginx
잘못 보고 502
닫 기 firewall
# systemctl stop firewalld
닫 기 selinux
#
setenforce 0
# selinux
getenforce
# ( )
vim /etc/selinux/config
SELINUX=disabled
STATIC_ROOT
을 사용 하고 python manage.py collectstatic
정적 파일 을 수집 합 니 다. 설정 nginx
의 /static
, 설정 nginx
중의 user
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.