Django + nginx + uwsgi 배치 (linux)

3219 단어
우선 당신 의 시스템 에 django, uwsgi, nginx 가 설치 되 어 있 는 지 확인 하 세 요. 구체 적 으로 인터넷 의 튜 토리 얼 을 어떻게 설치 하 는 지 확인 하 세 요. 여기 서 저 는 제 가 직면 한 문 제 를 몇 가지 쓰 겠 습 니 다.
* 우선
uwsgi 가 일 하 는 지 여 부 를 테스트 할 때 우 리 는 모두 xxx. py 파일 을 쓸 것 입 니 다. 다음 과 같 습 니 다.
def application(env, start_responce):
    start_responce("200 OK", [('Content-Type', 'text/html')])
    return [b"Hello World"] # python3
    # return ["Hello World"] # python2

실행: uwsgi -- http: 8000 -- wgi - file xxx. py 후 http: 127.0.1: 8000 로그 인
* 게다가
바로 uwsgi. ini 와 nginx. conf 의 설정 입 니 다. 아래 에 제 프로필 을 붙 입 니 다.
uwsgi. ini (아래 xxx 는 당신 의 django 프로젝트 이름 입 니 다. you 는 당신 의 / home / you /)
[uwsgi]
# Django-related settings
# socket = :8000
socket = /home/you/xxx/xxx.sock
chmod-socket = 666
uid = you
gid = you
# the base directory (full path)
chdir = /home/zbl/xxx
# Django s wsgi file
module = xxx.wsgi
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 4
# clear environment on exit
vacuum = true

xxx_nginx. conf (아래 xxx 는 django 프로젝트 이름 입 니 다. you 는 자신의 / home / you /)
# xxx_nginx.conf

# the upstream component nginx needs to connect to
upstream django {
    server unix:///home/you/xxx/xxx.sock; # for a file socket
    # server 127.0.0.1:8000; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
    # the port your site will be served on
    listen      80;
    # the domain name it will serve for
    server_name www.example.com; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    # location /media  {
    #     alias /path/to/your/mysite/media;  # your Django project's media files - amend as required
    # }

    location /static {
        alias /home/you/xxx/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /home/you/xxx/uwsgi_params; # the uwsgi_params file you installed
    }
}

마지막.
  • 위의 모든 경로 의 권한, 특히 프로젝트 디 렉 터 리 권한
  • 에 주의해 야 합 니 다.
    nginx error.log           .sock failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: www.xxxxx.com
    
    vim /etc/nginx/nginx.conf   -> user root
    
    -rw-rw-r--  1 you you  664 12  20 15:21 uwsgi_params
    -rw-r--r--  1 you you 1.1K 12  20 16:14 you_nginx.conf
    
  • 127.0.0.1 www. example. com 가입 / etc / hosts
  • ln - s / you / xxx 실행 권한nginx.conf /etc/nginx/sites-enabled/nginx
  • cp /etc/nginx/uwsgi_params /home/you/xxx
  • 재 부팅 명령 / etc / init. d / nginx restart
  • uwsgi 가 uwsgi uwsgi. ini 를 명령 한 후 http: 127.0.1 을 방문 하면 프로젝트 의 첫 페이지
  • 가 나타 날 것 입 니 다.
  • uwsgi 설치: * * sudo apt - get install libpcre 3 libpcre3 - dev * * sudo pip install uwsgi
  • nginx 설치 (인터넷 튜 토리 얼 은 많은 의존 도 를 설치 해 야 합 니 다): * * * sudo apt - get install nginx * * 방문 을 통 해http://localhost:80 테스트
  • 자신 이 직면 한 몇 가지 문제, 잘 쓰 지 못 했 습 니 다.

    좋은 웹페이지 즐겨찾기