
我們目前陷入這樣一種情況:我們使用nginx
Mesos-DNS 作為一組服務的主要前端伺服器,這些服務由基於動態 DNS 的服務發現提供支援。
我們的 nginx 設定看起來有點像這樣;
http {
resolver 10.10.1.1 valid=1s; // some internal DNS server
}
server {
set $core_api core-api-service.marathon.mesos; // some internal DNS
location /api {
proxy_pass $core_api:8080; // resolve core_api DNS dynamically to one of the IP's of the slave the process is running + listening on
}
}
現在的問題是這個設定工作正常,但是四到五個請求中的一個總是會導致 Nginx 返回 404,這是沒有意義的,因為集群內運行的服務都沒有移動到不同的從站。
現在,解析器valid=1s
非常激進,因此我們將其延長了更長的時間,認為這可能是查詢 DNS 太頻繁。但任何值都會導致同樣的問題。刪除valid=xx
也沒有幫助。
這裡發生了什麼事?我們如何緩解這種情況?
謝謝。
編輯(完整配置)
server {
listen 80;
server_name .myapp.com;
return 301 https://www.myappname.com$request_uri;
}
server {
listen 80;
gzip on;
gzip_min_length 1100;
gzip_buffers 4 32k;
gzip_types text/plain application/x-javascript text/xml text/css;
gzip_vary on;
root /usr/share/nginx/www;
index index.html index.htm;
include /etc/nginx/mime.types;
server_name api.myappname.com;
error_page 404 /static/404.html;
error_page 403 /static/404.html;
error_page 503 /static/503.html;
error_page 502 /static/502.html;
set $core_api http://core_api.marathon.mesos;
location /api {
if ($http_x_forwarded_proto != 'https') {
rewrite ^ https://$host$request_uri? permanent;
}
limit_req zone=one burst=35;
limit_req_status 503;
proxy_pass $core_api:8080;
proxy_set_header X-Real-IP $remote_addr;
}
}