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