간단 한 방법 으로 Flask + uwsgi + nginx 를 ubuntu 16.04 서버 에 배치 합 니 다.

3176 단어
인터넷 에서 검색 해 보 니 버 전이 유행 이 지난 이유 로 적용 되 지 않 는 방법 이 있 습 니 다. 제 배치 과정 을 간단하게 기록 해 보 세 요.텐 센트 클 라 우 드 서버 우 분투 16.04 LTS 초학 웹 개발 얼마 되 지 않 았 습 니 다.
1) nginx 설치
먼저 nginx 를 설치 하고 ubuntu 터미널 에서 실행 합 니 다.ubuntu@VM-252-231-ubuntu:~$ sudo apt install nginx
설치 에 성공 하면 클 라 우 드 서버 도 메 인 이나 ip 에 접근 하면 nginx 의 기본 페이지 가 나타 날 것 입 니 다.
2) 설치 uwsgi
가상 환경 을 사용 하려 면 가상 환경 디 렉 터 리 가 프로젝트 폴 더 아래 에 있 고 설치 해 야 할 가방 이 모두 설치 되 어 있다 고 가정 합 니 다. 이름 은 venv 입 니 다. 먼저 python - dev ubuntu@VM-252-231-ubuntu:~$ sudo apt install python-dev 를 설치 합 니 다.
그리고 가상 환경 활성화:
ubuntu@VM-252-231-ubuntu:~$ source venv/bin/activate```

          N ,              uwsgi 
  pip        ,     -i   ,           

`(venv) ubuntu@VM-252-231-ubuntu:~/N$ pip install uwsgi -i https://pypi.douban.com/simple`

##### 3)    uwsgi
            uwsgi ,   uwsgi                ,          :


[uwsgi] master = true home = venv
Flask 응용 실례 가 있 는 모듈
wsgi-file = manage.py
Flask 인 스 턴 스 이름
callable = app socket = 127.0.0.1:5000 stats = 127.0.0.1:9191
시스템 CPU 의 핵심 수 에 따라 결정 합 니 다.
processes = 4 threads = 4 buffer-size = 32768```
내 프로필 의 이름 은 uwsgi. ini 입 니 다. uwsgi 를 시작 하 라 는 명령 은 다음 과 같 습 니 다. (venv) ubuntu@VM-252-231-ubuntu:~/N$ uwsgi uwsgi.ini시작 에 성공 하면 알림 메시지 가 나타 납 니 다:
*** Operational MODE: preforking+threaded ***
WSGI app 0 (mountpoint='') ready in 2 seconds on interpreter 0x154fed0 pid: 3423 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 3423)
spawned uWSGI worker 1 (pid: 3428, cores: 4)
spawned uWSGI worker 2 (pid: 3429, cores: 4)
spawned uWSGI worker 3 (pid: 3430, cores: 4)
spawned uWSGI worker 4 (pid: 3431, cores: 4)
*** Stats server enabled on 0.0.0.0:9191 fd: 15 ***```

######  :                       uwsgi   ,         
    uwsgi      id :
`buntu@VM-252-231-ubuntu:~$ N ps -ef | grep uwsgi`
                  id   119911

tete 119911 117227 8 12:01 pts/20 00:00:01 uwsgi uwsgi.ini tete 119916 119911 0 12:01 pts/20 00:00:00 uwsgi uwsgi.ini tete 119917 119911 0 12:01 pts/20 00:00:00 uwsgi uwsgi.ini tete 119918 119911 0 12:01 pts/20 00:00:00 uwsgi uwsgi.ini tete 119922 119911 0 12:01 pts/20 00:00:00 uwsgi uwsgi.ini tete 119987 119933 0 12:01 pts/0 00:00:00 grep --color= auto -- exclude - dir =. bzr -- exclude - dir = CVS -- exclude - dir =. git -- exclude - dir =. hg -- exclude - dir =. svn uwsgi ` ` ` 이 프로 세 스에 SIGQUIT 를 보 내 면 uwsgi 를 닫 을 수 있 습 니 다. buntu@VM-252-231-ubuntu:~$ kill -s SIGQUIT 1199114) nginx 설정
현재 uwsgi 라 는 웹 서버 가 시작 되 었 습 니 다. 다음은 nginx 를 설정 합 니 다.가장 쉬 운 방법 은 / etc / nginx / sites - enabled / default 파일 을 직접 편집 하여 안의 모든 내용 을 삭제 하고 다음 내용 으로 바 꾸 는 것 입 니 다.
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /path/to/your/project;
    index index.html index.htm index.nginx-debian.html;

    server_name _;

        location / {
            uwsgi_pass 127.0.0.1:5000;
            include uwsgi_params;
}
}```

              ,      ,    
`ubuntu@VM-252-231-ubuntu:~$ sudo /etc/init.d/nginx reload`

좋은 웹페이지 즐겨찾기