○、結論
Nginx For Windows 建議使用
一、起因
項目中有一個 API 服務,對客戶端通信進行支持,大概 1w 客戶端,每分鐘都會進行通信。
高峯期的時候服務負載較高,爲了防止服務宕機,影響用戶,所以增加 Nginx 進行負載。
二、Windows 使用 Nginx
之前在 Linux 中使用 Nginx 並沒有什麼異常,現在的服務在 Windows Server 服務器上,所以就找 Nginx For Windows 的版本試一試。
nginx.conf 完整配置(負載均衡)如下:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024000;
}
http {
upstream as_server {
server 127.0.0.1:8901;
server 127.0.0.1:8902;
}
server {
listen 8099;
server_name localhost;
location / {
proxy_pass http://as_server;
}
}
}
三、worker_connections 坑
運行之後沒一會,服務就不響應了,查看錯誤日誌(logs\error.log)之後,發現提示 worker_connections 超出最大值了,但是配置文件裏明確配置的 1024000 ,看配置不應該出現此問題。
2019/07/16 21:28:49 [error] 13052#6092: *5451 maximum number of descriptors supported by select() is 1024 while waiting for request, client: 10.73.60.48, server: 0.0.0.0:8099
2019/07/16 21:28:49 [error] 13052#6092: *5454 maximum number of descriptors supported by select() is 1024 while waiting for request, client: 10.72.160.163, server: 0.0.0.0:8099
多番查詢後,發現 nginx for windows nginx-1.17.1 版本的 worker_connections 配置是編譯在軟件裏了,如果要改需要重新編譯。
四、最終的解決方案
訪問以下網址,可查看信息:
以下是最新版本下載地址: