0%

Flask Quickstart

code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# coding: utf-8

import logging
from flask import Flask


app = Flask(__name__)


@app.route('/')
def index():
logging.info("here is index")
return "<span style='color:red'>I am app 1</span>"


def main():
app.run('*', '8080')


if __name__ == '__main__':
main()

Development Server

$ python3 main.py

1
2
$ curl localhost:8080
<span style='color:red'>I am app 1</span>%

uWSGI

uwsgi.ini:

1
2
3
4
5
6
7
[uwsgi]
socket = 127.0.0.1:9090
wsgi-file = main.py
callable = app
processes = 4
threads = 2
stats = 127.0.0.1:9191

nginx:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;

server_name _;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.

uwsgi_pass 127.0.0.1:9090;
include uwsgi_params;

try_files $uri $uri/ =404;
}

# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
# fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

$ uwsgi --ini uwsgi.ini

1
2
$ curl localhost
<span style='color:red'>I am app 1</span>%