Ubuntu에서 Django 서빙을 위한 NGINX 프록시 설정



1. NGINX Proxy Pass To Gunicorn


드디어 마지막 편입니다. NGINX 프록시 패스를 Gunicorn으로 연결하는 작업이에요.

 

$> sudo nano /etc/nginx/sites-available/myproject


#/etc/nginx/sites-available/myproject

server {
    listen 80;
    server_name your_website.com;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/web/myprojectdir;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }
}

 

1편에서 이미 nginx를 설치했으니 위 명령어로 새로운 사이트 설정파일을 만들어 줍니다. 그리고 위에 설정처럼 입력하시고 세이브하시는데요. 위는 혹시 static을 서버에서 서빙하시는 분들을 위함이고요. 저는 S3를 통해서 서빙할것이기 때문에 아래 설정은 삭제해 줍니다.

location /static/ {
    root /home/web/myprojectdir;
}

 

이제 저장한 세팅을 nginx폴더 안에 sites-enabled로 넣어주고 nginx를 재시작 하기전에 테스트를 해줍니다. 그 후 Syntax에 이상이 없으면. nginx를 재시작해주고 방화벽을 열어줍니다.

$> sudo ln -s /etc/nginx/sites-available/yayax /etc/nginx/sites-enabled
$> sudo nginx -t

#output
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

$> sudo systemctl restart nginx
$> sudo ufw allow 'Nginx Full'

 

 

2. Troubleshooting!


문제가 있으시면 아래 커맨드로 확인 가능합니다.

  • NGINX 프로세스 로그 확인: sudo journalctl -u nginx
  • NGINX 엑세스 로그 확인: sudo less /var/log/nginx/access.log
  • NGINX 에러 로그 확인: sudo less /var/log/nginx/error.log
  • GUNICORN 어플리케이션 로그 확인: sudo journalctl -u gunicorn
  • GUNICORN 소켓 로그 확인: sudo journalctl -u gunicorn.socket
  • GUNICORN 데몬 Reload: sudo systemctl daemon-reload
  • GUNICORN 재시작: sudo systemctl restart gunicorn



  • [[a.original_name]] ([[a.file_size | fileSizer]])
'Django 배포하기' 시리즈 포스트
Ubuntu 에서 Django 가상환경으로 배포하기
2020-10-11
Ubuntu에서 Django 서빙을 위한 NGINX 프록시 설정
2020-10-11
Ubuntu로 Django 파일 업로드 Gunicorn 서비스 소켓 생성
2020-10-11
좋아요[[ postLike | likePlus ]]
공유
라이언

“Lead Python Engineer”

댓글 [[totalCommentCount]]
[[ comment.author__nick_name ]] [[ comment.datetime_updated | formatDate]] (수정됨)

[블라인드 처리된 글 입니다.]

답장
[[ sub.author__nick_name ]] [[ sub.datetime_created | formatDate ]] (수정됨)

취소
댓글을 남겨주세요.
'Django' 관련 최신 포스트
[[ post.title ]]
[[ post.datetime_published_from | DateOnly ]]