From installing a server with Flask, which tends to be complicated
Implementation is in Implementation
Without this For example, when using a certain Web server (A) Web application (A') that hijacked the specification Will have to be used (actually it seems to have been done in the past) And vice versa
WSGI is a standardized form of that specification. Obviously, Flask to be used from now on is also hijacking the WSGI specifications
Django is the main Python framework Compared to Django, it has only the minimum necessary functions Super lightweight and easy to implement
Used by Netflix, Reddit, etc.
$ sudo apt update
Package update
$ sudo apt upgrade
Install development tools such as gcc and gdb (required to build uwsgi)
$ sudo apt install build-essential
install openssl
$ sudo apt install openssl
Install pip3
$ sudo apt install python3-pip
install ufw
$ sudo apt install ufw
Close all ports
$ sudo ufw default deny
Keep the required ports open In my case SSH (22), http (80)
$ sudo ufw allow 22
$ sudo ufw allow 80
Enable firewall
& sudo ufw enable
Check status
$ sudo ufw status
By the way, when connecting with SSH If you do not follow this order, you will not be able to connect Be careful as there is a possibility
Until installation if you do not need to install the latest version separately Skip it and OK
Download PGP key
$ wget https://nginx.org/keys/nginx_signing.key
Import key
$ sudo apt-key add nginx_signing.key
Register repository
$ sudo vi /etc/apt/sources.list
#Add to the end bionic part is ubuntu development code
deb http://nginx.org/packages/ubuntu/ bionic nginx
deb-src http://nginx.org/packages/ubuntu/ bionic nginx
The bionic part of ~ / ubuntu / bionic nginx is Rewrite according to Ubuntu version
version | Development code |
---|---|
16.04 | xenial |
18.04 | bionic |
19.10 | eoan |
20.04 | focal |
How to check ubuntu version
$ cat /etc/lsb-release
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
Update repository information
sudo apt update
Check version
$ apt show nginx
Package: nginx
Version: 1.18.0-1~bionic
At the time of writing the article, 1.18.0 seems to be a stable version
http://nginx.org/en/download.html You can check if it is the latest version with
--- This is how to install the latest version --- </ b>
Installation
$ sudo apt install nginx
Version confirmation
$ nginx -v
nginx version: nginx/1.18.0
Register for the service in advance
$ sudo systemctl enable nginx
$ sudo systemctl start nginx
Success if accessible
$ curl http://localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
...
If port 80 is open From allowed IP
$ curl http://<Public IP>
But check
$ sudo pip3 install virtualenv
Version confirmation
$ virtualenv --version
Create environment
$ virtualenv py36_flask_server --python=python3.6
By the way, if the specified version of Python is not included Install it in advance as it will fail to create
OK if you put it in the environment below
$ . <Environment name>/bin/activate
(py36_flask_server) ubuntu@ip-10-0-0-14:~$
$pip3 install uwsgi
Check version
$uwsgi --version
By the way, there was also a way to use Anaconda instead of Virtualenv. However, please note that errors occur frequently at the stage of installing uWSGI.
If you want to use Anaconda It will take time, but it will be solved, so refer to the following article https://katsuwosashimi.com/archives/300/python-conda-install-uwsgi-failed/
$pip3 install flask
that's all
Next is Implementation
Recommended Posts