Ubuntu Server18.04에 django2.를 배치합니다.0+python3.7

3083 단어 webDjangolinux
  • 1, ip귀속vim/etc/mysql/mysql.conf.d/mysqld.cnf 수정bind-address = 127.0.0.1은 0.0.0.0으로 원격 접근을 지원합니다.
  • 2, 사용자 만들기 원격 접근 1. 사용자 만들기:CREATE USER'admin'@'%'IDENTIFIED BY'admin123'username: 사용자 이름;host: 어느 호스트에 로그인할 수 있는지 지정합니다. 이 호스트는localhost를 사용할 수 있고% 는 모든 원격 호스트에 연결됩니다.password: 사용자 로그인 비밀번호;2. 권한 부여: GRANT ALL PRIVILEGES ON.TO ‘admin’@‘%’ IDENTIFIED BY 'admin123’;
  • 3, pip freeze>requirements를 사용합니다.txt 개발 환경 내보내기
  • 4, 배포 환경의 가상 환경으로 복사하려면 pip install -r requirements를 사용합니다.txt를 가상 환경에 설치합니다.
  • 5,sudo apt install libpython3.7-dev 설치 uwsgi 오류 방지.
  • 6, uwsgi pip install uwsgi 설치
  • 7, dbeaver를 사용하여 새로운 데이터베이스 가져오기
  • 8, 프로젝트 루트 디렉터리에서 uwsgi 테스트: uwsgi --http: 8000 --modu firtproject.wsgi가 페이지를 표시하지만 스타일이 없으면 성공을 설명합니다.
  • 9, 프로젝트 디렉터리에서uc 만들기nginx.conf
  • # the upstream component nginx needs to connect to
    upstream django {
    # server unix:///path/to/your/mysite/mysite.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   ip   ; # 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     /Mxonline/media;  #   django media  
    }
    
    location /static {
        alias     /Mxonline/static; #   django static  
    }
    
    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     uwsgi_params; # the uwsgi_params file you installed
    }
    }
    
  • 10, 서버name을 IP 주소나 도메인 이름으로 변경합니다.및 프로젝트 경로 이름
  • 11,/etc/nginx/conf.d 아래 sudo ln -s 디렉터리/Mxonline/conf/nginx/uc 에 복사 또는 링크nginx.conf/etc/nginx/conf.d/
  • 12, 재부팅nginx
  • 13, STATIC 추가ROOT = os.path.join(BASE DIR, "static/") 및 staticfiles 주석 달기dirs 속성.setting에 가서 정적 파일을 추출합니다.
  • 14, 정적 파일python 관리자를 끌어옵니다.py collectstatic
  • 15, 새 uwsgi.ini 프로필, 내용은 다음과 같습니다:
  •     # mysite_uwsgi.ini file
        [uwsgi]
    
        # Django-related settings
        # the base directory (full path)
        chdir           = /home/***/Projects/ #     
        # Django's wsgi file
        module          =      .wsgi
        # the virtualenv (full path)
    
        # process-related settings
        # master
        master          = true
        # maximum number of worker processes
        processes       = 10
        # the socket (use the full path to be safe
        socket          = 127.0.0.1:8000
        # ... with appropriate permissions - may be needed
        # chmod-socket    = 664
        # clear environment on exit
        vacuum          = true
        virtualenv = virtualenv    /    
    
        logto = /tmp/mylog.log
    
     :
        chdir:          ,        .
        module: wsgi     
        processes:    
        virtualenv:       
    
  • 16,workon은 가상 환경에서 uwsgi를 실행하면 방금 설정한 파일 이름을 받을 수 있습니다.uwsgi - i/절대 경로/uwsgi.ini & 백엔드 실행
  • pkill if uwsgi
    참조 링크:django 배치 강좌

    좋은 웹페이지 즐겨찾기