Django+Uwsgi+Nginx 의 생산 환경 배치 에 대한 자세 한 설명
준비 조건:
1.runserver 로 정상적으로 시작 할 수 있 는 django 프로젝트 가 있 는 지 확인 합 니 다.
2.프로젝트 가 linux 에 업로드 됨
3.Liux 에 python 환경 이 배치 되 어 있 고 프로젝트 에 필요 한 모듈 이 설치 되 어 있 습 니 다.
설치
uwsgi 는 python 의 모듈 입 니 다.uwsgi 를 설치 하려 면 간단 한 pip 명령 만 있 으 면 됩 니 다.
pip3 install uwsgi
uwsgi+django 기반 실현1.명령 으로 uwsgi 시작
STEP 1:django 프로젝트 진입

두 번 째 단계:명령 테스트 시작
uwsgi --http 192.168.31.123:8080 --file teacher/wsgi.py --static-map=/static=static

매개 변수 설명:
--http 이것 은 runserver 와 같이 IP 포트 를 지정 한다
--file 이 파일 에 반사 되 어 있 습 니 다.그 를 호출 할 때 웹 서버 를 지정 하지 않 으 면 기본 값 을 사용 합 니 다.
--static 에서 맵 을 만들어 정적 파일 을 지정
이때http://192.168.2.108:8080/그림 에서 보 듯 이 프로젝트 가 성공 적 으로 시작 되 었 음 을 나타 낸다.

2.uwsgi 프로필 로 django 프로젝트 시작
첫 번 째 단계:django 프로젝트 동급 디 렉 터 리 에 script 디 렉 터 리 를 만 들 고 설정 스 크 립 트 를 저장 하 는 데 사용 합 니 다.

두 번 째 단계:/script 디 렉 터 리 에 들 어가 uwsgi.ini 파일 을 만 듭 니 다.
uwsgi.ini 파일 을 편집 하 는 내용 은 다음 과 같 습 니 다.
# uwsig
[uwsgi]
#
chdir=/opt/proj/teacher/
# application
module=teacher.wsgi:application
# sock
socket=/opt/proj/script/uwsgi.sock
#
workers=5
pidfile=/opt/proj/script/uwsgi.pid
# IP
http=192.168.2.108:8080
#
static-map=/static=/opt/proj/teacher/static
# uwsgi
uid=root
gid=root
#
master=true
# unix Socket pid
vacuum=true
# ,
thunder-lock=true
#
enable-threads=true
#
harakiri=30
#
post-buffering=4096
#
daemonize=/opt/proj/script/uwsgi.log
시작 항목:
192.168.2.108:8080 방문,시작 성공

이로써 uwsgi+django 는 완벽 하 게 결합 되 었 습 니 다.그러나 uwsgi 만 으로 는 부족 합 니 다.uwsgi 는 동적 요청 을 처리 하 는 능력 이 높 지만 정적 요청(예 를 들 어 static 파일,css,js 파일 등)에 대한 처리 능력 이 떨 어 집 니 다.이때 nginx 와 결합 하여 사용 해 야 합 니 다.
설치 nginx
STEP 1:yum 원본 설정
vim /etc/yum.repos.d/nginx.repo
파일 내용 은 다음 과 같 습 니 다.wq 저장 종료
STEP 2:nginx 설치
yum -y install nginx
설치 완료 여부,명령 시작 nginx
/etc/init.d/nginx start

브 라 우 저 를 열 고 192.168.2.108 에 다음 페이지 가 나타 나 면 nginx 설치 가 완료 되 고 정상적으로 시작 할 수 있 습 니 다.

STEP 3:장고+Uwsgi+Nginx
먼저 설정 파일 을 만 듭 니 다.nginx 의 기본 설정 디 렉 터 리 는/etc/nginx/conf.d 입 니 다.

teacher.conf 파일 만 들 기

설정 내용 은 다음 과 같 습 니 다.
server { # server
listen 80; #
server_name 192.168.2.108 ; # url
access_log /var/log/nginx/access.log main; # Nginx
charset utf-8; # Nginx
gzip_types text/plain application/x-javascript text/css text/javascript application/x-httpd-php application/json text/json image/jpeg image/gif image/png application/octet-stream; #
error_page 404 /404.html; #
error_page 500 502 503 504 /50x.html; #
# uwsgi
location / { # location Django url(r'^admin/', admin.site.urls),
include uwsgi_params; # Nginx uWSGI
uwsgi_connect_timeout 30; # uWSGI
uwsgi_pass unix:/opt/proj/script/uwsgi.sock; # uwsgi sock
}
#
location /static/ {
alias /opt/proj/teacher/static/;
index index.html index.htm;
}
}
마지막 단계,nginx 다시 시작
/etc/init.d/nginx restart

브 라 우 저 방문 192.168.2.108,다음 페이지 가 나타 나 면 시작 성공 을 표시 합 니 다.

nginx 관련 명령
# Nginx Nginx
/etc/init.d/nginx start
/etc/init.d/nginx stop
# configtest,Nginx , ,
/etc/init.d/nginx configtest
# Nginx , stop start restart reload
#
/etc/init.d/nginx reload
이로써 Django+Uwsgi+Nginx 의 생산 환경 배치 가 완료 되 었 습 니 다.이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Django 라우팅 계층 URLconf 작용 및 원리 해석URL 구성(URLconf)은 Django가 지원하는 웹 사이트의 디렉토리와 같습니다.그것의 본질은 URL과 이 URL을 호출할 보기 함수 사이의 맵표입니다. 위의 예제에서는 URL의 값을 캡처하고 위치 매개 변수로...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.