# Flask Generated on 11 Dec 2023 from [the Flask catalog page](https://marketplace.digitalocean.com/apps/flask) Flask is an extensible web micro-framework written in Python. Designed to get started as quickly and easily as possible with the ability to scale up, Flask is a great solution for projects of any size and complexity. ## Software Included | Package | Version | License | |---|---|---| | NGINX | 1.18.0 | [Custom](http://nginx.org/LICENSE) | | Certbot | 1.21.0 | [Apache 2](https://github.com/certbot/certbot/blob/master/LICENSE.txt) | | Gunicorn | 20.1.0 | [MIT License](https://github.com/benoitc/gunicorn/blob/master/LICENSE) | | Flask | 3.0.0 | [BSD-3-Clause](https://flask.palletsprojects.com/en/2.2.x/license/) | ## Creating an App using the Control Panel Click the **Deploy to DigitalOcean** button to create a Droplet based on this 1-Click App. If you aren’t logged in, this link will prompt you to log in with your DigitalOcean account. [![Deploy to DO](https://www.deploytodo.com/do-btn-blue.svg)](https://cloud.digitalocean.com/droplets/new?image=flask) ## Creating an App using the API In addition to creating a Droplet from the Flask 1-Click App using the control panel, you can also use the [DigitalOcean API](https://docs.digitalocean.com/reference/api). As an example, to create a 4GB Flask Droplet in the SFO2 region, you can use the following `curl` command. You need to either save your [API access token](https://docs.digitalocean.com/reference/api/create-personal-access-token/index.html.md) to an environment variable or substitute it in the command below. ```shell curl -X POST -H 'Content-Type: application/json' \ -H 'Authorization: Bearer '$TOKEN'' -d \ '{"name":"choose_a_name","region":"sfo2","size":"s-2vcpu-4gb","image":"flask"}' \ "https://api.digitalocean.com/v2/droplets" ``` ## Getting Started After Deploying Flask After your droplet is created, you can access your Flask stack by typing the droplet’s IP address in your browser: ![Flask Welcome Page](https://do-not-delete-droplet-assets.nyc3.digitaloceanspaces.com/flask.png) If you see the *Site can’t be reached* or *Nginx 502 Bad Gateway*, give it 2-3 minutes and reload the page. Flask droplet ships a simple Flask project with static files, wsgi server, gunicorn service running wsgi and nginx proxy to gunicorn. - The sample project can be found in /`home/flask/flask_project` - WSGI server is in `/home/flask/flask_project/wsgi.py` - Gunicorn systemd service can be found in `/etc/systemd/system/gunicorn.service` - Gunicorn socket is located at `/home/flask/gunicorn.socket` ## Configuring Nginx After you have created your Flask droplet, it is highly recommended you configure an Nginx server block file for each site you plan to host. Doing so will make the default configuration the fallback, as intended, and will make it easier to manage changes when hosting multiple sites. To do so, you’ll need to create two things for each domain: a new directory in /var/www for that domain’s content, and a new server block file in /etc/nginx/sites-available for that domain’s configuration. For a detailed walkthrough, follow [How to Set Up Nginx Server Blocks](https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-16-04). ## Adding a domain name A domain name allows others to access your website with an encrypted connection if you intend to host a website on your Flask Droplet 1-Click. Flask Droplet 1-Click comes with certbot installed, making it easier to enable HTTPS on your 1-Click. First, ensure your domain points to the new droplet IP. If your DNS is managed by DigitalOcean, it should look like this: ![Flask DNS Example](https://do-not-delete-droplet-assets.nyc3.digitaloceanspaces.com/Screenshot%202023-03-21%20at%2014.15.01.png) The DNS Host may be the same company you registered the domain with or another entity you designate. To connect your DNS hosting to DigitalOcean, check out [this guide](https://docs.digitalocean.com/tutorials/dns-registrars/). After you have configured the domain and nginx, you can run certbot to acquire HTTPS certificates for your droplet: ![Flask Certbot Example](https://do-not-delete-droplet-assets.nyc3.digitaloceanspaces.com/Screenshot%202023-03-21%20at%2014.34.31.png) After you answer questions from certbot, your HTTPS setup is finished. Use your domain in the web browser to access your Flask Droplet. ## Droplet Summary - UFW firewall allows only SSH (port 22, rate limited), HTTP (port 80), and HTTPS (port 443) access. - The Flask Droplet comes with the *flask* user. - Sample Flask application is located at /home/flask/flask\_project. - Sample Flask application is hosted via gunicorn as a systemd service. - Service is located at /etc/systemd/system/gunicorn.service - *flask* user credentials can be found at /root/.digitalocean\_passwords