Nginx+Gunicorn

2395 단어
1.Nginx
설치 하 다.
sudo apt-get install nginx

시작, 정지, 재 부팅
sudo /etc/init.d/nginx start
sudo /etc/init.d/nginx stop
sudo /etc/init.d/nginx restart

or
sudo service nginx start
sudo service nginx stop
sudo service nginx restart

설정 nginx
편집 / etc / nginx / sites - enabled / default 감청 포트 설정, 정적 파일 설정
vim /etc/nginx/sites-enabled/default
upstream django1 { 
     server unix:///home/www/company/company.sock; # for a file socket
     #server 127.0.0.1:8011; # for a web port socket (we'll use this first)
}
# configuration of the server

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=off;

    location / {
        proxy_pass http://your IP:8000;#change your port
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    location /static {
        alias /your project path/static/; # your Django project's static files - amend as required
    }
    location /media  {
        alias /your project path/media;  # your Django project's media files - amend as required
    }

}


한 서버 에 여러 항목 을 배치 할 때 주의해 야 합 니 다.
테스트 프로필:
nginx -t

서비스 다시 시작:
sudo service nginx restart
python manage.py collectstatics 

Gunicorn
설치 하 다.
pip install gunicorn

gunicorn 의 간단 한 용법:
gunicorn code:application

다 중 핵 처리 장치 에서 8 개의 프로 세 스 를 동시에 시작 하여 HTTP 요청 을 처리 합 니 다.
 gunicorn -w 8 code:applcation

django +gunicorn:
INSTALLED_APPS = ( 
    'django.contrib.admin',
    'django.contrib.auth',  
    'django.contrib.contenttypes', 
    'django.contrib.sessions',  
    'django.contrib.messages',
    'django.contrib.staticfiles', 
    # add app 
    'yourapp',
    'gunicorn',
 )

프로젝트 파일 에서 실행:
$ nohup gunicorn project.wsgi:application -b 127.0.0.1:1010&

nohup 은 파일 nohup command > my out. file 2 > & 1 & 그리고 tail 로 nohup. out 을 볼 수 있 습 니 다. 아무런 정보 도 없 으 면 됩 니 다.

좋은 웹페이지 즐겨찾기