Member-only story
Setup Flask-Nginx-SSL
Setup Flask-Nginx-SSL
Step 1:
Install the Pre-Requiresties:
sudo apt-get install python3-pip python3-dev Nginx
create virtualenv
activate virtualenv
Install the gunicorn inside the virtualenv that you have created now
pip install gunicorn
Step 2:
Create WSGI File in your project home directory:
vim project/wsgi.py
Paste this below code into wsgi.py file
from views import app#Here views is my flask run server file, you #can mention your run server package
if __name__ == “__main__”:
app.run()
To check wsgi configuration run the following command:
gunicorn — bind 0.0.0.0:5000 wsgi:app
or
gunicorn -b localhost:5000 -w 4 flask_app:app
Now deactivate the virtualenv
deactivate virtualenv
Step 3:
Create a systemd Unit File
systemd unit file will allow Ubuntu’s init system to automatically start Gunicorn and serve our Flask application whenever the server boots.
Create a unit file ending in .service within the /etc/systemd/system directory to begin :
sudo vim /etc/systemd/system/app.service