Skip to content
This repository was archived by the owner on Feb 11, 2020. It is now read-only.
This repository was archived by the owner on Feb 11, 2020. It is now read-only.

Mosca, Docker, Reverse Proxy and Real IP #790

Open

Description

@KingRial

Hello everyone.

Right now I am using Mosca as an MQTT Broker inside a docker container offering "MQTT" and "MQTT over websocket" protocols.
The challenge I am facing right now is that, because of an humongous problem of docker, the client IP I get from client.connection.stream.remoteAddress is not the correct one.

Normally, when using HTTP protocol, to solve the problem the solution is just adding a reverse proxy before the docker container which add "X-Forwarded-For" header with the real IP to the request.
Such solution just works with HTTP procotols.

Using an nginx server as a reverse proxy, I am adding the header over the websocket request to Mosca:

location / {
	proxy_pass http://{{MOSCA SERVER}}:{{PORT TO WEBSOCKET}};

	# redirect all HTTP traffic
	proxy_set_header Host $host;
	proxy_set_header X-Real-IP $remote_addr;
	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

	# WebSocket support (nginx 1.4)
	proxy_http_version 1.1;
	proxy_set_header Upgrade $http_upgrade;
	proxy_set_header Connection "upgrade";
}

The added header seems completly ignored by Mosca and I am not understanding if that's correct or if mosca is just lacking the correct support.

Is there any way to get the real IP from websocket connection ?
Or should I follow this idea ?

Any hint would be much appreciated.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions