Facing wss connection failed on nginx side. We are using nginx as reverse proxy. I searched on google it was showing required following config but after putting following config under stream it giving error as “nginx: [emerg] “location” directive is not allowed here in”. so I put same config under http section but getting another error as bind failed on 443.
To enable reverse proxy for web-sockets you will need to put your configuration inside http block.
Following are the minimum required configs to enable websockets for Hivemq broker.
server {
listen 8001; #please make sure port is not used by any other process
server_name localhost; # use your server name or ip
location /mqtt {
proxy_pass "http://localhost:8000/mqtt"; #use the port you have actually configured in your Hivemq config.xml.
proxy_connect_timeout 1s;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
}
Of course you can add SSL/TLS Termination configurations to same server block.
Also if you want to forward real ip to broker you will need to have proxy protocol feature enabled. This is a HiveMQ Enterprise Edition feature.
I configured the same config under http block it giving bind error on port 443.
Actually on nginx stream block is configured and when I put above config in server section of stream it showing error as location is not allowed in stream so I google it and put it under http block but it was giving bind 443.
I think nginx stream and http both want to bind on port 443 and this is making issue.
Thanks for reply. HiveMQ 3.3.3 is already reached end of life. We would recommend updating to the supported hivemq version.
It is not supported to listen on same port (443) in http and stream hence you are getting error with binding port. To resolve issue you will need to change port either for stream block or http block. We would recommend to use 8883 instead of 443 port for stream block.
Thanks for quick response. My nginx stream config as under and I have doubt, do we have /mqtt is directory on hivemq installation location? because we are putting config on nginx to location search under /mqtt. My hivemq server running on 8883 I am using nginx as reverse proxy but due do wss issue I am stuck.