Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 Python Flask Deployment Guide

This repository is used for deploying a Python Flask application on a Linux server using Nginx as a reverse proxy.


🧰 Tools & Technologies Used


📦 Prerequisites

  • A Linux server (e.g., Amazon EC2)
  • Port 80 (HTTP) and port 5000 (Flask default) opened in the security group
  • Git installed on the server
  • Nginx installed

🛠️ Step-by-Step Setup

1️⃣ Clone the Repository

SSH into your server and install Git:

sudo yum install git -y

Clone the repository:

git clone https://github.com/yourusername/your-repo-name.git
cd your-repo-name

2️⃣ Install Python and pip

Install Python 3 and pip:

sudo yum install python3-pip -y

3️⃣ Install Flask and Other Dependencies

Create a requirements.txt file:

flask

Install all dependencies:

pip3 install -r requirements.txt

4️⃣ Run the Flask App

Start the Flask app:

python3 app.py

It will run on:

http://<your-server-ip>:5000

⚠️ Flask App Stops on Logout?

To keep the app running in the background:

nohup python3 app.py &

To store logs in a file:

nohup python3 app.py > output.log 2>&1 &

🔍 Monitor or Stop the App

Check if it's running:

ps aux | grep app.py

Stop the app:

pkill -f app.py

🌐 Run on Port 80 with Nginx

1️⃣ Install Nginx

sudo yum install nginx -y

2️⃣ Configure Nginx

Edit the config file:

sudo vi /etc/nginx/conf.d/flask-app.conf

Paste this:

server {
    listen 80;
    server_name 34.228.170.42;

    location / {
        proxy_pass http://34.228.170.42:5000;
        proxy_http_version 1.1;
        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;
    }
}

3️⃣ Start and Enable Nginx

sudo systemctl start nginx
sudo systemctl enable nginx

Now you can visit:

http://34.228.170.42

Without the port number!


✅ Summary

  • Clone repo → Install Python & pip → Install Flask via requirements.txt
  • Use nohup to run Flask persistently
  • Configure Nginx to expose app on port 80

🧼 Optional Maintenance

Check running processes:

ps aux | grep app.py

Kill app:

pkill -f app.py

View logs:

cat output.log

📬 Need Help?

Open an issue in this repo or reach out!

About

Deploying Sample Python Application

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages