This project implements a Flask web application with SSL support and an nginx reverse proxy. The application allows users to submit messages which are stored in a JSON file and displayed on the home page. This project is divided into 6 tasks, where each task has its own functionalities as given in the project statement. The overview of the setup is given below:
- Flask Web Application: Handles user messages and stores them in a JSON file.
- SSL/TLS Encryption: Ensures secure communication.
- nginx Reverse Proxy: Forwards requests to the Flask application.
- Python 3.x
Flask
librarynginx
reverse proxy
-
Clone the Repository
git clone https://github.com/yourusername/your_flask_app.git cd your_flask_app
-
Create and Activate a Virtual Environment
python3 -m venv venv source venv/bin/activate
-
Install Dependencies
pip install -r requirements.txt
-
Install nginx
sudo apt-get update sudo apt-get install nginx
-
Configure nginx
Create a configuration file for your Flask app:
sudo nano /etc/nginx/sites-available/your_flask_app
Add the following content:
server { listen 80; server_name yourdomain.com; location / { proxy_pass https://IP_ADRESS; 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; } }
-
Enable the Site
Create a symbolic link to enable the site:
sudo ln -s /etc/nginx/sites-available/your_flask_app /etc/nginx/sites-enabled/
-
Test nginx Configuration
sudo nginx -t
-
Restart nginx
sudo systemctl restart nginx
-
Start the Flask App
python app.py
Ensure the Flask application is set to run with SSL:
if __name__ == '__main__': app.run(host="0.0.0.0", port=5000, debug=True, ssl_context=('certB.pem', 'keyB.pem'))
Create the certificates with the following command:
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365
This is a general file structure, generally file structure is varied upon different tasks.
your_flask_app/
│
├── app.py
├── user_data.json
├── requirements.txt
├── templates/
│ └── index.html
└── README.md