Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Host Config & Reverse Proxy #297

Closed
banyu-wigara opened this issue Jan 18, 2022 · 7 comments
Closed

Host Config & Reverse Proxy #297

banyu-wigara opened this issue Jan 18, 2022 · 7 comments

Comments

@banyu-wigara
Copy link

I've tried this package, but it seems I can't decide which interface I want to listen to when starting the service like what if I want to listen for private IP only?
And just want to know if this package would be better with or without reverse proxy like Nginx

@rennokki
Copy link
Member

what if I want to listen for private IP only?

Trying to understand this. Do you mean how to keep soketi non-public and use it just internally, for your other services?

And just want to know if this package would be better with or without reverse proxy like Nginx

Both are good. Adding reverse proxy adds some latency, but solves some configurational burdens when running in shared hosting with another backend app, especially for SSL.

@banyu-wigara
Copy link
Author

@rennokki Yes, I want to put the websocket service for private use and also I want to have another one for public use but It's going to be behind Nginx, but the problem is the websocket service is listening to "0.0.0.0" or all interface, I want to know if it's possible to set which interface to listen to, like for the the one behind nginx will we "127.0.0.1" and the one for private will be "PRIVATE_IP"

@rennokki
Copy link
Member

HOST environment variable. It's not documented, I guess 😓

@francislavoie
Copy link

francislavoie commented Jan 25, 2022

Shameless plug, but I recommend using Caddy as your reverse proxy for this. Caddy has Automatic HTTPS, it can fetch certs from Let's Encrypt or ZeroSSL automatically. And you can use request matchers to decide to proxy to socketi instead of your PHP (or whatever) app if the request looks like websockets.

Example config, works for your standard Laravel app:

example.com {
	log

	@ws {
		header Connection *Upgrade*
		header Upgrade websocket
	}
	handle @ws {
		reverse_proxy socketi:6001
	}

	handle {
		root * /srv/public
		encode gzip
		php_fastcgi php-fpm:9000
		file_server
	}
}

@rennokki feel free to add this to the docs 👍

@elbojoloco
Copy link

elbojoloco commented Feb 11, 2022

@xiCO2k Thank you for promoting Caddy here! Your reply has resulted in my entirely dropping nginx on my webserver and migrating everything, including the the reverse proxy for my websocket setup. This is so beautiful:

ws.mydomain.example {
        reverse_proxy 127.0.0.1:6001

        @websockets {
                header Connection *Upgrade*
                header Upgrade websocket
        }

        reverse_proxy @websockets 127.0.0.1:6001
}

@francislavoie
Copy link

In your case @elbojoloco since you're using the same upstream for both websockets and non-websockets, you don't need the @websockets matcher at all. Just do this:

ws.mydomain.example {
    reverse_proxy 127.0.0.1:6001
}

@elbojoloco
Copy link

In your case @elbojoloco since you're using the same upstream for both websockets and non-websockets, you don't need the @websockets matcher at all. Just do this:

ws.mydomain.example {
    reverse_proxy 127.0.0.1:6001
}

Wow, amazing.. thanks for the tip!

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

No branches or pull requests

4 participants