pcarrier / srv.us

ssh to expose local HTTP services online, CLI pastebin, etc.
https://docs.srv.us
BSD Zero Clause License
87 stars 8 forks source link

Having Port for the public address #32

Open alanmilinovic opened 8 months ago

alanmilinovic commented 8 months ago

Is it possible to have port? Like this pcarrier.gh.srv.us:8088 and of course stil have a secure connection with SSL.

pcarrier commented 6 months ago

Sorry but not today, everything goes through a single port and the hostname is used to differentiate between instances. What would be the use case, if you don't mind sharing?

alanmilinovic commented 6 months ago

Simply having multiple applications tunneled on a different ports and avoid doing revers proxy.

pcarrier commented 6 months ago

You can have multiple applications on multiple ports, they'll each get a unique hostname. We show that in examples like https://docs.srv.us/#demo. Is that not acceptable?

alanmilinovic commented 6 months ago

You can have multiple applications on multiple ports, they'll each get a unique hostname. We show that in examples like https://docs.srv.us/#demo. Is that not acceptable?

I am talking about a public hostname, that is always without a port. It is ok to have unique hostname for every application, but I am missing having the port for example: jdoe.gh.srv.us:8088

pcarrier commented 6 months ago

You have a port, it's 443. If you want another one I'd like to understand the use case.

alanmilinovic commented 6 months ago

You have a port, it's 443. If you want another one I'd like to understand the use case.

I know, can there be other ports that I can use?

pcarrier commented 6 months ago

We're running in circles. What's the use case for a different port please? Why not separate hostnames instead? I'm open to considering your problem I just need to know what it is.

alanmilinovic commented 6 months ago

Ok, so basically, I have applications listening on different ports that I both use locally when I am at home and also when I leave my house. Whenever I am calling those applications I use javascript "window.location.hostname:8088" when constructing my url. That way I automated easily when I am at home I use local IP plus port and when I am outside it will switch to public hostname plus port.

Another example is Home Assistant application, where I use iframe feature, where you need to specify url. I construct url also the same way by using javascript window.location. As Home Assistant mobile application can have internal and external address, it is resolved depending whether you are connected to the home wifi or on mobile internet, so my iframe is then also perfectly resolved if I use the same port.

More info here: https://community.home-assistant.io/t/new-addon-access-machines-in-your-homenet-with-apache-guacamole-ingress-support/209829/56?u=alanmilinovic

Now, when I am inside my local network I have port 8088 for example and outside for public network I have 443 port, I have a mismatch and windows.location.hostname+'8088' will not work dynamically.

pcarrier commented 6 months ago

I see, thanks. Have you considered putting everything on the same port with different hostnames and/or paths through proxying, eg via nginx?

It could look something like this for distinct paths:

http {
  server {
    listen [::]:80 reuseport;
    listen 80 reuseport;
    location / {
      proxy_pass http://127.0.0.1:8080;
    }
    location /foo {
      proxy_pass http://127.0.0.1:8081;
    }
    location /bar {
      proxy_pass http://127.0.0.1:8082;
    }
  }
}

While it'd be theoretically possible to allow for more ports for the same hostname, I'm not quite sure how you'd choose them through ssh's interface (the flag -R remoteport:localaddress:localport doesn't have any extra space given I already use remoteport to map to a hostname).

alanmilinovic commented 6 months ago

I see, thanks. Have you considered putting everything on the same port with different hostnames and/or paths through proxying, eg via nginx?

It could look something like this for distinct paths:

http {
  server {
    listen [::]:80 reuseport;
    listen 80 reuseport;
    location / {
      proxy_pass http://127.0.0.1:8080;
    }
    location /foo {
      proxy_pass http://127.0.0.1:8081;
    }
    location /bar {
      proxy_pass http://127.0.0.1:8082;
    }
  }
}

While it'd be theoretically possible to allow for more ports for the same hostname, I'm not quite sure how you'd choose them through ssh's interface (the flag -R remoteport:localaddress:localport doesn't have any extra space given I already use remoteport to map to a hostname).

Thanks for a reply. Yes I am proxying a lot, but there are some apps that doesn't work or have problems when I proxy them, mostly because of bad architecture and "base url" that is not working.

Hm, I can see the challenge around ssh interface and syntax. Not sure how to handle it but happy to test it if you can make any feasible solution.