Skip to content

This repository provides a production-ready template for deploying a Flask web server behind an Nginx reverse proxy on AWS Lightsail Containers. It includes setup instructions, deployment scripts, and logging/monitoring commands to help you quickly and securely launch your Flask application in a scalable environment.

Notifications You must be signed in to change notification settings

CynthiaWahome/lightsail-nginx-flask

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deploying Flask with Nginx Reverse Proxy on AWS Lightsail

AWS Docker Nginx

A production-ready template for deploying a Flask web server behind an Nginx reverse proxy on AWS Lightsail Containers.


Table of Contents


Overview

Deploy a secure, scalable Flask app with:

  • Nginx Reverse Proxy: Routes traffic to Flask and hides backend details.
  • AWS Lightsail Containers: Managed Docker hosting with simplicity.
  • Isolated Environments: Separate containers for proxy and app logic.

Prerequisites


Setup & Deployment

1. Clone the Repository

git clone https://github.com/CynthiaWahome/lightsail-nginx-flask.git
cd lightsail-nginx-flask

2. Build and Test Locally

# Build Flask
docker build -t flask-container ./flask

# Build Nginx
docker build -t nginx-container ./nginx

# Run containers
docker run -d -p 5000:5000 --name flask-app flask-container
docker run -d -p 80:80 --name nginx-proxy --link flask-app nginx-container

3. Deploy to AWS Lightsail

# Create service
aws lightsail create-container-service \
  --service-name my-service \
  --power small \
  --scale 1

# Push images (replace X/Y with your versions)
aws lightsail push-container-image \
  --service-name my-service \
  --label flask-container \
  --image flask-container

aws lightsail push-container-image \
  --service-name my-service \
  --label nginx-container \
  --image nginx-container

# Deploy
aws lightsail create-container-service-deployment \
  --service-name my-service \
  --containers file://containers.json \
  --public-endpoint file://public-endpoint.json

Logging & Monitoring

# Nginx logs
aws lightsail get-container-log \
  --service-name my-service \
  --container-name sample-nginx \
  --log-type "nginx-access"

# Flask logs
aws lightsail get-container-log \
  --service-name my-service \
  --container-name sample-flask \
  --log-type "flask"

Cleanup

aws lightsail delete-container-service --service-name my-service

FAQ

Q: Why 502 Bad Gateway?
A: Check FLASK_HOST in containers.json matches the Flask container name.

Q: How to add HTTPS?
A: Configure SSL in Nginx and use AWS Certificate Manager (ACM).


License

This project is licensed under the Apache License 2.0. See the LICENSE file for more details.

About

This repository provides a production-ready template for deploying a Flask web server behind an Nginx reverse proxy on AWS Lightsail Containers. It includes setup instructions, deployment scripts, and logging/monitoring commands to help you quickly and securely launch your Flask application in a scalable environment.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published