Article From:https://www.cnblogs.com/xueweihan/p/9060065.html

1, agreement consistency

uWSGI It is behind nginx, so the protocol that nginx forwarding requests is consistent with the protocol of uWSGI monitoring. Otherwise, there will be problems, because it is the communication between the three.
Nginx -> uWSGI -> app

1.1 uWSGI exception information”

invalid request block size: 21573 (max 4096)...skip

If the following configuration occurs, the above abnormality will appear.

# Nginx To configureLocation / {Proxy_pass http://127.0.0.1:6000;}Collocation with uWSGI configurationUwsgi --socket: 6000 --wsgi-file app.py

1.2 Nginx exception information”

upstream prematurely closed connection while reading response header from upstream, client: 120.xxx.xxx.xxx, server: hellogithub.com, request: "GET / HTTP/1.1", upstream: "uwsgi://127.0.0.1:6000", host: "hellogithub.com"

The reason is: nginx is uwsgi protocol, uWSGI is HTTP protocol, then the request can not reach uWSGI.

1.3 correctly configures the example:

1.Passing the request through the uwsgi protocol

# Nginx To configureLocation / {Include uwsgi_params;Uwsgi_pass 127.0.0.1:6000;}Collocation with uWSGI configurationUwsgi --socKet: 6000 --wsgi-file app.py

The above configuration means that “each request is passed to port 6000, which is bound by the server, and communicated with the uwsgi Protocol”.

2.Passing the request through the HTTP protocol (not recommended)

# Nginx To configureLocation / {Proxy_set_header Host $host;Proxy_set_header X-Real-IP$remote_addr;Proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;Proxy_passHttp://127.0.0.1:6000;}Collocation with uWSGI configurationUwsgi --http: 6000 --wsgi-file app.py

Each request is passed to the 6000 port service through the HTTP protocol, but the service application wants to obtain the requested real IP and the requested HTTP information to be configured in the nginx.

two, configuration parameter

2.1 specifies the configuration file to start.”

1.Remember that there is a pidfile parameter in the configuration file

pidfile=/tmp/myproject-master.pid 

Otherwise, supervisor restart uWSGI will not shut down the process, and it will not report errors.

TODOThis may lead to another exception. If I use the specified INI file to start up, I will report this problem.

robably another instance of uWSGI is running on the same address (:6000).
bind(): Address already in use [core/socket.c line 769]

2.2 to start gevent

uwsgi --gevent 100 --gevent-monkey-patch --http :9090 -M --processes 4 --wsgi-file wsgi.py

increase--gevent-monkey-patch Parameters can be activated in gevent mode without modifying the code.

2.3 environment variable”

supervisor The configured environment variables will not be passed on to the services initiated by uWSGI. For instance:

## supervisor To configureEnvironmenit=name=hellogithubApp code fragmentPro_name = os.getenv ('name')

At this timepro_name Will returnNone Rather than expectedhellogithub,So when you start uWSGI, you need to increase the parameters of the environment variables.--env name=hellogithub,So it can be expected.

three, reference

  • uWSGI File

Similar Posts:

Link of this Article: UWSGI trample

Leave a Reply

Your email address will not be published. Required fields are marked *