Flask Web App deployment with Nginx Proxy server on ProxMox LXC container, Azure AI Speech Web App.

Deploy Flask with Nginx on LXC: A Quick Guide

In this easy-to-follow tutorial, we’ll guide you through deploying a Flask web app using Nginx on an LXC Container. This container is smoothly running on ProxMox, with Ubuntu 23.04 as the chosen LXC version. We’ve opted for LXC because of its lightweight nature and its impressive capability to serve our web app efficiently, even with limited server resources.

1. Create a new LXC container on the ProxMox, and use Ubuntu 23.04 Standard for the container version.

2. As soon as the LXC is up and running, we need to add new user:

3. Update the system, then install python3-pip and python3-venv

4. create a python virtual environment, and activate it:

5. Install Gunicorn

6. At this point I assume your Flask Web App is already created and ready to be deployed on the LXC server. Either use git clone or upload the code into server directly. Then install all dependencies of Flask web app from requirements.txt (pip3 install -r requirements.txt)

Another option, you can create a python file name as flask.py and add simple codes below:

7. Run the Flask web app and double check if it’s running.

and you may see similar results as below:

8. Create a gunicorn web server gateway interface file- wsgi.py and put below code:

9. We need a system service to serve the Gunicorn without manual interaction, idea is to make sure the web app is automatically up and running each time the server powers up. Create a flaskapp.service file and save it with below codes:

Note: The -w option at ExecStart specifies the number of processes to run; a starting value could be CPU * 2. The default is only 1 worker, which is probably not what you want for the default worker type. For more please check out Flask Official documentation басыңыз

10. Enable auto start, start and check status:

11. Install Nginx:

12. Add Flask Web App config file on Nginx:

13. Unlink Nginx Default site then check the syntax:

Here is the output if test is successful:

Reload Nginx

At this point our Flask Web app is up and running via Nginx

14. Finally, we need to update the firewall rules on the server, remove unnecessary ports that allowed, check the firewall status:

Result:

Note: Please make sure you have added firewall rule for ssh port 22, otherwise you will lose remote connection:

Leave a Reply

Э-пошта мекенжайыңыз жарияланбайды. Міндетті өрістер * таңбаланған