Get the App
SLTechnology News&Howtos  ›  Servers  › 

Nginx+uwsgi runs python application

Shulou Source: shulou.com Published: 2022-06-03 03:30:12 09月16日 Update

Reference:

Http://www.bjhee.com/nginx-uwsgi.html

1. Install uwsgi

Pip install uwsgi

(apt install uwsgi)

2. Run a file through http, such as test.py

Uwsgi-- http: 80-- wsgi-file test.py-- master-- processes 4-- threads 2-- stats 127.0.0.1

The "--http" parameter specifies the HTTP listening address and port

The-- wsgi-file "parameter specifies the WSGI application entry

UWSGI will start 4 application processes, each with 2 threads, and a master main process (monitor the status of other processes and restart if any of them die)

Visit "127.0.0.1 9090" to get the application running information in JSON format

You can write the parameters into a file

Cat myapp.ini

[uwsgi]

Http=:80

Wsgi-file=test.py

Master=true

Processes=4

Threads=2

Stats=127.0.0.1:9090

Start

Uwsgi myapp.ini

3. Configure nginx

Change the HTTP port snooping of uWSGI to socket port snooping. Remove the "http" entry in the configuration file and change it to "socket":

[uwsgi]

Socket=127.0.0.1:9090

Wsgi-file=test.py

Master=true

Processes=4

Threads=2

Stats=127.0.0.1:9191

The nginx configuration file is

Location / {

Include uwsgi_params

Uwsgi_pass 127.0.0.1:9090

}

Start

Service nginx restart

Uwsgi myapp.ini

-

Cat uwsgi_params

Uwsgi_param QUERY_STRING $query_string

Uwsgi_param REQUEST_METHOD $request_method

Uwsgi_param CONTENT_TYPE $content_type

Uwsgi_param CONTENT_LENGTH $content_length

Uwsgi_param REQUEST_URI $request_uri

Uwsgi_param PATH_INFO $document_uri

Uwsgi_param DOCUMENT_ROOT $document_root

Uwsgi_param SERVER_PROTOCOL $server_protocol

Uwsgi_param REQUEST_SCHEME $scheme

Uwsgi_param HTTPS $https if_not_empty

Uwsgi_param REMOTE_ADDR $remote_addr

Uwsgi_param REMOTE_PORT $remote_port

Uwsgi_param SERVER_PORT $server_port

Uwsgi_param SERVER_NAME $server_name

Tags: Process file application parameter port monitor configure run information entry address application format status program thread reference monitor Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Linux Shulou Tech Info Apple NVidia