sudo apt-get install nginx gunicorn3 -y
파일이 index.py
이고 flask 변수 이름이 app
일 때 아래와 같이 실행해서 정상 동작하는지 확인한다.
gunicorn3 --bind 0.0.0.0:80 index:app
gunicorn3 --bind unix:`pwd`/gunicorn.sock index:app
vim /etc/systemd/system/<이름>.service
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=root
Group=root
WorkingDirectory=<플라스크 파일 디렉토리 위치>
ExecStart=/usr/bin/gunicorn3 \
--workers 4 \
--bind unix:/<플라스크 파일 디렉토리 위치>/gunicorn.sock index:app &
[Install]
WantedBy=multi-user.target
vim /etc/nginx/sites-enabled/default
기본 포트를 8080같은걸로 변경하고 ipv6를 사용하지 않으면 2번째 줄은 주석 처리한다.
server {
listen 8080 default_server;
#listen [::]:80 default_server;
.
.
.
}
sudo systemctl daemon-reload
sudo systemctl enable <이름>
sudo systemctl start <이름>
sudo systemctl status <이름>
도메인이 있다면 server_name에는 도메인을 넣으면 된다.
vim /etc/nginx/conf.d/<이름>.conf
server {
listen 80;
server_name <IP>;
client_max_body_size 20M;
location / {
proxy_pass http://unix:/root/hq/gunicorn.sock;
}
}
위에서 client_max_body_size
로 파일 전송의 최대 크기를 지정할 수 있다.
sudo systemctl restart nginx <이름>