Web applications developed in python language are not like PHP, which can be accessed directly by placing them in a directory. It is necessary to configure the web service in the python environment, and then in order to unify the use of domain names and ports, you can use nginx to configure it to provide external services. access:

nginx configuration is as follows:

    location / {
        include                uwsgi_params;
        uwsgi_send_timeout     600;
        uwsgi_connect_timeout  600;
        uwsgi_read_timeout     600;
        uwsgi_pass             127.0.0.1:81;
    }

The three lines in the middle are mainly used to set the timeout. In order to cooperate with some complex Python calculations, if the running time is very short, you don’t need to add it;

The last line of port can be filled in according to the situation, and cooperates with the uwsgi below;

python install uwsgi:

pip3 install uwsgi

Create a new configuration file uwsgi.ini

[uwsgi]
socket=127.0.0.1:81
plugins = python3
wsgi-file=app.py 
master=true
processes=4
threads=2
stats=127.0.0.1:82
callable=app

They are designated ports, programs, file names, number of processes, monitoring addresses, etc.;

The last line is to configure the Flask framework, otherwise you don’t need this line;

Create a new program file app.py

def application(env, start_response):
    start_response('200 OK', [('Content-Type','text/html')])
    return [b"Hello World"]

Open a screen under the shell, run uwsgi uwsgi.ini, the browser accesses the domain name configured by nginx, and displays Hello World normally;

If using the Flask framework, refer to Flask's standards to modify the app.py file.

Reference: https://www.runoob.com/python3/python-uwsgi.html






Leave a Reply