Client IP for websockets behind a nginx proxy

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

brainlag
Posts: 2
Joined: 18 Jan 2017, 10:27

Client IP for websockets behind a nginx proxy

Postby brainlag » 18 Jan 2017, 10:34

We are using a smartfox websockets application behind a nginx websockets proxy, which leads to all client requests coming from the IP of the proxy server, not the real client IP. nginx is setting X-Forwarded-For and X-Real-IP headers, which is working fine for most backend stacks e.g. rails but is not honoured by the smartfox server.
Is there a way to identify the real IP of the client in SFS2X 2.12?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Client IP for websockets behind a nginx proxy

Postby Lapo » 18 Jan 2017, 15:09

Hi,
I am not familiar with the inner workings of nginx but this doesn't sound like an SFS issue.
The client connection is going through a proxy and therefore it is expected that the server will see all clients coming from the same source. As to how this can be changed I don't know but it's definitely a task for the proxy server.

Maybe it's an issue with websockets in nginx?
Lapo
--
gotoAndPlay()
...addicted to flash games
brainlag
Posts: 2
Joined: 18 Jan 2017, 10:27

Re: Client IP for websockets behind a nginx proxy

Postby brainlag » 18 Jan 2017, 15:20

It's not a "bug" per se in SFS2 and nginx is working as expected in proxy mode. Services running behind a proxy are very common and most backend server stacks have an option to retrieve the real IP of the client or are using the X-Forwarded-For header to set it accordingly. Is that possible with SFS2?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Client IP for websockets behind a nginx proxy

Postby Lapo » 18 Jan 2017, 15:29

No, at least not as of SFS2X 2.12 which implements websockets via Netty 3.x.
We're planning to replace the implementation via Jetty 9.x in the near future, and we'll investigate if this is possible, which I think it is (according to their docs).

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
trungnt85
Posts: 16
Joined: 10 Jun 2017, 03:58

Re: Client IP for websockets behind a nginx proxy

Postby trungnt85 » 05 Jul 2017, 09:45

Hi Lapo,

Is there any way I can get specific headers from a connection?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Client IP for websockets behind a nginx proxy

Postby Lapo » 05 Jul 2017, 10:24

Hello,
could you expand on your request and explain what you're trying to achieve exactly?

The websocket protocol doesn't support custom headers, unless maybe for the initial "UPGRADE" request. I'd like to better understand what is the use case.

thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
trungnt85
Posts: 16
Joined: 10 Jun 2017, 03:58

Re: Client IP for websockets behind a nginx proxy

Postby trungnt85 » 05 Jul 2017, 10:31

Hi,

My problem is I have my game on iOS, Android and Web. I don't enable WSS on my Smartfox server, it's all okay till I need to deploy web version under secure domain, so I have to establish a proxy, on which I secure connect to specific port then proxy will pass the request to Smartfox server. But as the topic, I cannot capture real ip from users which is mandatory for analytics. I've already enable X-Forward-for Configuration on jetty. Now how can I get X-Forward-For header Jetty captured?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Client IP for websockets behind a nginx proxy

Postby Lapo » 05 Jul 2017, 14:02

Hi,
trungnt85 wrote:Hi,
My problem is I have my game on iOS, Android and Web. I don't enable WSS on my Smartfox server, it's all okay till I need to deploy web version under secure domain, so I have to establish a proxy

Why is this?
I mean, why do you need a proxy for secure domain instead of just running WSS and avoid the problem entirely?

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Client IP for websockets behind a nginx proxy

Postby Lapo » 05 Jul 2017, 14:05

Back to your question:
I've already enable X-Forward-for Configuration on jetty. Now how can I get X-Forward-For header Jetty captured?

It's not possible to do what you're asking. We don't support it, I am afraid.
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
trungnt85
Posts: 16
Joined: 10 Jun 2017, 03:58

Re: Client IP for websockets behind a nginx proxy

Postby trungnt85 » 06 Jul 2017, 03:39

Thanks Lapo,

For some reason I cannot upgrade client library to support secure socket yet, might have to leave it to next phase.

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 73 guests