harbor run -t LiteCoder/nginx-https-flask-reverse-proxyharbor download LiteCoder/nginx-https-flask-reverse-proxySet up Nginx as a reverse proxy with SSL/TLS termination to securely serve a Python Flask application running on localhost:5000.
Create a Flask application at /app/app.py with the following requirements:
0.0.0.0:5000.GET / — returns a JSON response {"status": "ok", "message": "Hello from Flask"} with content type application/json.GET /health — returns a JSON response {"healthy": true} with content type application/json.Generate a self-signed SSL certificate and key:
/etc/nginx/ssl/server.crt/etc/nginx/ssl/server.keyConfigure Nginx as a reverse proxy at /etc/nginx/conf.d/flask_proxy.conf (or modify the appropriate Nginx config) with these requirements:
443 with SSL enabled.https://localhost/ are proxied to http://127.0.0.1:5000.proxy_pass directive pointing to the Flask backend.proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;nginx -t succeeds).Configure Nginx to listen on port 80 and redirect all HTTP traffic to HTTPS (port 443).
After setup, the following must hold true:
http://127.0.0.1:5000/.systemctl is-active nginx or equivalent returns active, or the nginx process is running).nginx -t reports configuration is valid.curl -k https://localhost/ returns the JSON {"status": "ok", "message": "Hello from Flask"}.curl -k https://localhost/health returns the JSON {"healthy": true}./etc/nginx/ssl/server.crt is a valid PEM certificate.proxy_pass directive pointing to http://127.0.0.1:5000.