I have a java spring application deployed in a tomcat 8 environment in Amazon elastic beanstalk server. The application has HTTPS configured with proper certificate. When a socket connection connect the application I am getting below error in log
ERROR o.s.w.s.s.s.DefaultHandshakeHandler - Handshake failed due to invalid Upgrade header: null
I tried to figure out over internet, some post is saying it need to enable HTTPS. HTTPS is already enabled and normal webservice calls to the same server works.
Please let me know if anyone has any idea. Thank you !
The problem is the elastic beanstalk uses a proxy, so you can configure the proxy to support sockets.
The default proxy to Tomcat is Apache, I have changed it to nginx with the next file:
.ebextensions\nginx-proxy.config
option_settings:
aws:elasticbeanstalk:environment:proxy:
ProxyServer: nginx
then I added my nginx file:
.ebextensions\files.config
files: "/etc/nginx/conf.d/01_websockets.conf" : mode: "000644" owner: root group: root content : | worker_processes 1;
events {
worker_connections 2024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name localhost;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
# prevents 502 bad gateway error
proxy_buffers 8 32k;
proxy_buffer_size 64k;
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
# enables WS support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
}
Good luck!!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With