我对我的 nginx 服务器使用以下配置:
upstream django {
server unix:///var/www/example.com/django/ws/django.socket;
}
upstream io_nodes {
ip_hash;
server 127.0.0.1:8080;
}
limit_req_zone $binary_remote_addr zone=one:100m rate=1000r/s;
server {
listen 80;
server_name example.com;
root /var/www/example.com;
location /static {
alias /var/www/example.com/media;
}
location / {
limit_req zone=one burst=500 nodelay;
uwsgi_pass django;
include /etc/nginx/uwsgi_params;
}
location /socket.io/ {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_pass http://io_nodes;
}
}
当我向 /socket/message 发送 POST 请求时,只有 5 个请求会立即处理,其余的请求将被延迟。一段时间后,将处理接下来的 5 个请求,依此类推。因此,我认为这与 limit_req 设置有关,但将其设置为非常高的值并没有帮助。那么问题可能是什么?