Run Nginx with Flask in Windows OS
How to run Nginx with Flask in Windows OS. It’s hard to get a one-stop article that contains all the information to implement these in Windows. The upstream servers where the incoming requests will be redirected need to be mentioned like below: You can add as many servers as you like depending on the load. It’s recommended the upstream servers need to be in separate machines. However the same IP also can be mentioned. Nginx server can be SSL supported. This is a sample code. The WSGI server with You can follow this link to run Nginx as a service in windows. Here the app from Flask is used to route the API URLs we get as HTTP requests. As Flask server is highly recommended to not use in production server, Cherrypy is doing the purpose here. Run Nginx with Flask in Windows OS
Nginx is used as a load balancer, with its reverse proxy server. Design diagram of the set-up
Nginx config
upstream backend {
server <IP1>:<port1>;
server <IP2>:<port2>;
server <IP3>:<port3>;
}
Configuring HTTPS changes
upstream backend {
server 127.0.0.1:8020;
server 127.0.0.1:8021;
server 127.0.0.1:8022;
}
# HTTPS server
server {
listen 8019 ssl;
server_name 11.222.33.444;
ssl_certificate "<certificate.pem file absolute path>";
ssl_certificate_key "<certificate_key.pem file absolute path>";
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root html;
proxy_pass https://backend/;
}
}
Cherrypy
and Flask
# sample app with flask
=
"""
Processes with app
"""
=
Related Articles