英文:
Spring WebSocket behind Nginx works with Tomcat but not with Undertow
问题
我已经将Tomcat替换为Undertow,以减少我的Spring WebSocket应用程序的内存使用。在本地一切正常运行。然而,当我将我的应用程序放在Nginx代理下时,客户端无法连接到WebSocket端点,出现错误{"code":1006, "text": "unexpected EOF"}。
这是我的Nginx配置,对Tomcat有效但对Undertow无效。
location /ws/ {
proxy_pass http://chat:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
# WebSocket
proxy_connect_timeout 4s;
proxy_read_timeout 15m;
proxy_send_timeout 12s;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
我还在我的application.properties中添加了server.forward-headers-strategy=native
。是否有人知道我是否遗漏了Undertow或Nginx的某些内容?
英文:
I have replaced Tomcat with the Undertow to reduce memory usage on my spring WebSocket application. Everything works fine locally. However, when I put my application under an Nginx proxy, the client cannot connect to the WebSocket endpoint with the error {"code":1006, "text": "unexpected EOF"}.
Here is my config for Nginx, this works for tomcat but not for Undertow.
location /ws/ {
proxy_pass http://chat:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
# WebSocket
proxy_connect_timeout 4s;
proxy_read_timeout 15m;
proxy_send_timeout 12s;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
I also add server.forward-headers-strategy=native
to my application.properties.
Does anyone know if something I missed for Undertow or Nginx?
答案1
得分: 0
在搜索了许多网站之后,我终于在这里找到了解决方案。将proxy_http_version 1.1;
添加到配置中可以解决这个问题。
英文:
After searching lots of websites, I finally found the solution in here. Adding proxy_http_version 1.1;
to the config can resolve the problem.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论