gunicorn
Dockerを使った方が良いと思うが、今回は簡単にサーバー上でバックグラウンドで実行する。
gunicorn -b 127.0.0.1:8080 -k flask_sockets.worker server:app -D
-Dオプションでバックグラウンド。nginxでローカルからのアクセスになるため、127.0.0.0だけを許可する。アプリケーション名は都度考える。
停止
バックグラウンドで実行しているとctr+cでは止められない。$ps aux | grep gunicorn でプロセスidを確認して $ kill id で止める。
Nginx
# for websocket
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}
server {
	listen 80;
	listen [::]:80;
	server_name example.com;
	return 301 https://$host$request_uri;
}
server {
	listen 443 ssl;
	ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;
	ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
	proxy_set_header Host $http_host;
	proxy_set_header X-Forwarded-Proto $scheme;
	proxy_http_version 1.1; # for websocket
	proxy_set_header Upgrade $http_upgrade;
	proxy_set_header Connection $connection_upgrade;
	server_name example.com;
	charset UTF-8;
	location / {
		proxy_pass http://localhost:8080;
	}
}
proxy_pass http://localhost:8080; でローカルのアプリケーションにアクセスする。
参考
Nginx+gunicorn構成でFlaskを使う[ローカル環境編] – Qiita
  
  
  
  


Comments