This repository is used for deploying a Python Flask application on a Linux server using Nginx as a reverse proxy.
- 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
SSH into your server and install Git:
sudo yum install git -yClone the repository:
git clone https://github.com/yourusername/your-repo-name.git
cd your-repo-nameInstall Python 3 and pip:
sudo yum install python3-pip -yCreate a requirements.txt file:
flaskInstall all dependencies:
pip3 install -r requirements.txtStart the Flask app:
python3 app.pyIt will run on:
http://<your-server-ip>:5000
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 &Check if it's running:
ps aux | grep app.pyStop the app:
pkill -f app.pysudo yum install nginx -yEdit the config file:
sudo vi /etc/nginx/conf.d/flask-app.confPaste 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;
}
}sudo systemctl start nginx
sudo systemctl enable nginxNow you can visit:
http://34.228.170.42
Without the port number!
- Clone repo → Install Python & pip → Install Flask via
requirements.txt - Use
nohupto run Flask persistently - Configure Nginx to expose app on port 80
Check running processes:
ps aux | grep app.pyKill app:
pkill -f app.pyView logs:
cat output.logOpen an issue in this repo or reach out!