将请求分发至同一主机的不同端口(不考虑容器)
解决的问题:
将请求分发至同一主机的不同端口(不考虑容器)
支持:
https
upstream api {
server 127.0.0.1:5000 weight=1;
server 127.0.0.1:5001 weight=1;
server 127.0.0.1:5002 weight=1;
}
server {
server_name paper.com;
location / {
proxy_pass http://api;
proxy_ssl_certificate /etc/letsencrypt/live/paper.com/fullchain.pem; # managed by Certbot
proxy_ssl_certificate_key /etc/letsencrypt/live/paper.com/privkey.pem; # managed by Certbot
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/paper.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/paper.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
(base) paper@kn:~# ps -ef | grep py
paper 463 1 0 Jun28 ? 00:00:00 /usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers
paper 561 1 0 Jun28 ? 00:00:00 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal
paper 2594 2484 0 Jun28 ? 00:00:18 /usr/bin/python2 /usr/bin/supervisord -n -c /etc/supervisord.conf
paper 17314 1 0 Jun29 ? 00:00:00 python3 manage.py runserver 0.0.0.0:5000
paper 17552 17314 4 Jun29 ? 00:47:04 /paper/anaconda3/bin/python3 manage.py runserver 127.0.0.1:5000
paper 23970 1 0 10:05 ? 00:00:00 python3 manage.py runserver 0.0.0.0:5001
paper 23973 23970 7 10:05 ? 00:02:18 /paper/anaconda3/bin/python3 manage.py runserver 0.0.0.0:5001
paper 24076 1 0 10:06 ? 00:00:00 python3 manage.py runserver 0.0.0.0:5002
paper 24079 24076 9 10:06 ? 00:02:44 /paper/anaconda3/bin/python3 manage.py runserver 0.0.0.0:5002
paper 24515 24393 0 10:36 pts/4 00:00:00 grep --color=auto py
检查端口使用情况
1、压测的限流告警
throttled X-API-VERSION[:9]:2.0.14.58;request.X-REQUEST-ID[:36]:c17caf67-2ab7-4bec-8776-14d36c50ef45;request.META[:567]:{'REQUEST_METHOD': 'GET', 'QUERY_STRING': '', 'SCRIPT_NAME': '', 'PATH_INFO': '/api/test/news/list/', 'wsgi.multithread': True, 'wsgi.multiprocess': True, 'REMOTE_ADDR': '127.0.0.1', 'REMOTE_HOST': '127.0.0.1', 'REMOTE_PORT': 57490, 'SERVER_NAME': '127.0.0.1', 'SERVER_PORT': '5002', 'HTTP_HOST': 'api.jubaotime.com', 'HTTP_REMOTE_HOST': '121.35.100.120', 'HTTP_X_FORWARDED_FOR': '121.35.100.120', 'HTTP_X_FORWARDED_PROTO': 'https', 'HTTP_X_REAL_IP': '121.35.100.120', 'HTTP_CONNECTION': 'upgrade', 'HTTP_USER_AGENT': 'Apache-HttpClient/4.5.12 (Java/15-ea)'};request.headers[:240]:{'Host': 'api.jubaotime.com', 'Remote-Host': '121.35.100.120', 'X-Forwarded-For': '121.35.100.120', 'X-Forwarded-Proto': 'https', 'X-Real-Ip': '121.35.100.120', 'Connection': 'upgrade', 'User-Agent': 'Apache-HttpClient/4.5.12 (Java/15-ea)'};request.body[:3]:b''throttle_limit:128throttle_window_second:32