Deployment tips
Hello. Thanks for the game. It's great. I was trying to deploy it on my local server to play using Nginx as a reverse proxy and uwsgi as a server for your flask project, but it doesn't work correctly.
It would be really great if you tell how you deployed it.
Thank you in advance.
I use flask run directly to run the server, but also have nginx sitting in front of it. Here's my nginx config, let me know if there's anything else you need.
upstream web_backend {
server 127.0.0.1:5000;
}
server {
listen 80;
server_name www.kfchess.com;
# ssl redirect
if ($http_x_forwarded_proto = "http") {
return 301 https://$server_name$request_uri;
}
# static stuff
location ~ ^/static/ {
root /var/www/kfchess;
gzip_static on;
expires 30d;
}
# backend stuff
location ~ ^/api/ {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://web_backend;
}
location /login {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://web_backend;
}
location /logout {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://web_backend;
}
location /socket.io {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://web_backend;
# enables websockets
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
# dist stuff
location /bundle.js {
alias /var/www/kfchess/dist/bundle.js;
gzip_static on;
expires -1;
}
location ~ ^/img/ {
root /var/www/kfchess/dist;
gzip_static on;
expires -1;
}
# fallback to index.html
location /index.html {
alias /var/www/kfchess/index.html;
expires -1;
}
location /favicon.ico {
alias /var/www/kfchess/favicon.ico;
expires 30d;
}
location / {
try_files $uri /index.html;
}
}
Thank you for the config.
Mine looks kinda same. It works fine using flask run and nginx, but I cant deploy it using uwsgi. I've tried tons of different uwsgi and nginx configurations yet didn't get any 100% working solution.
Also, I got error in browser console : WebSocket connection to 'ws://myserver.com/socket.io/?EIO=3&transport=websocket&sid=0514a0aa99f346e7ad717770f9911c89' failed: WebSocket is closed before the connection is established. with any config or with flask run.
BTW if you could add an example nginx conf to readme.md as a deploy tip it would be great.
UPD uwsgi didn't work with any kind of configuration, so I moved to guicorn. Guicorn works really good, also it is super simple.