Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Nginx+uwsgi runs python application

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report