我正在尝试使用 Vaadin(Java、Spring Boot)、NGINX 和 Tomcat 正确配置 LONG POLLING 推送。
有时 Push 会停止工作,我怀疑这可能是我的设置中某些配置错误的原因。
问题:
推送意外停止工作,直到使用 F5 硬刷新页面。这里的关键点是问题的意外性质。但是,普通的 XHR 请求继续正常工作。目前,Vaadin 团队正在努力验证 Vaadin/Atmosphere 方面的所有内容。除此之外,我想检查 LONG POLLING 的系统配置是否正确。
在我的手机上,我每天都会遇到几次这个问题。我甚至无法使用 F5 刷新网站。除了手动断开 Wi-Fi 连接外,没有其他办法。iPhone 自动切换到 LTE,应用程序立即开始正常工作。似乎有什么东西导致应用程序锁定...
您能否验证我的配置是否存在问题(尤其是超时、缓冲区等):
Vaadin/Spring Boot/Tomcat 配置:
server.servlet.session.persistent=false
server.servlet.session.timeout=30m
server.servlet.session.tracking-modes=cookie
server.servlet.session.cookie.http-only=true
server.servlet.session.cookie.secure=true
server.servlet.session.cookie.max-age=365d
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=common
vaadin.whitelisted-packages=com.vaadin,org.vaadin,com.examle
vaadin.heartbeatInterval=30
vaadin.pushLongPollingSuspendTimeout=25000
vaadin.maxMessageSuspendTimeout=5000
vaadin.closeIdleSessions=false
vaadin.eagerServerLoad=false
NGINX 配置:
server {
sendfile on;
tcp_nodelay on;
tcp_nopush on;
etag off;
if_modified_since off;
proxy_buffering off;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_cache off;
proxy_cache_convert_head off;
proxy_max_temp_file_size 0;
client_max_body_size 0;
proxy_http_version 1.1;
proxy_pass_request_headers on;
proxy_pass_request_body on;
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_send_timeout 300;
reset_timedout_connection on;
proxy_redirect off;
resolver 77.88.8.8 77.88.8.1 8.8.8.8 8.8.4.4 valid=1d;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types
application/atom+xml
application/geo+json
application/javascript
application/x-javascript
application/json
application/ld+json
application/manifest+json
application/rdf+xml
application/rss+xml
application/xhtml+xml
application/xml
font/eot
font/otf
font/ttf
image/svg+xml
text/css
text/javascript
text/plain
text/xml;
location / {
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Frame-Options "ALLOW-FROM blog.example.com";
add_header Access-Control-Allow-Origin example.com;
add_header Access-Control-Allow-Origin blog.example.com;
add_header Content-Security-Policy "frame-ancestors example.com blog.example.com";
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_send_timeout 300;
include /etc/nginx/snippets/cors.conf;
proxy_pass http://127.0.0.1:8080;
proxy_redirect http://127.0.0.1:8080 /;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
}
我还sysctl
向 Linux 添加了以下属性:
sysctl -w net.ipv4.tcp_retries2=5
sysctl -w net.ipv4.tcp_keepalive_time=300
sysctl -w net.ipv4.tcp_keepalive_intvl=1
sysctl -w net.ipv4.tcp_keepalive_probes=5