Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


What is the best way to route subdomain to port
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

What is the best way to route subdomain to port

FritzFritz Veteran

Hi,

What is the best way to access port using subdomain?

Can HaProxy or Traefik help solve this?

Anyone knows simple guide for this?

Comments

  • If you are using Cloudflare (free) there's a one-click app in their store. It's free to use to route subdomain to port its called Portzilla.

  • jnraptorjnraptor Member
    edited December 2020

    Maybe try using caddy?

    https://caddyserver.com/docs/quick-starts/reverse-proxy

    Contents of Caddyfile:
    sub.domain.com reverse_proxy 127.0.0.1:9000

    Then do a caddy run in the same directory as the caddyfile.

    Thanked by 1yoursunny
  • FritzFritz Veteran
    edited December 2020

    @JasonM said:
    If you are using Cloudflare (free) there's a one-click app in their store. It's free to use to route subdomain to port its called Portzilla.

    Thank you but I prefer hosted solution instead.

    @jnraptor said:
    Maybe try using caddy?

    https://caddyserver.com/docs/quick-starts/reverse-proxy

    Contents of Caddyfile:
    sub.domain.com reverse_proxy 127.0.0.1:9000

    Then do a caddy run in the same directory as the caddyfile.

    I already have Nginx on port 80 and on port 9000 I already have something listening on that port.

    Will thay interfere the service running on port 9000?

  • edited December 2020

    Use nginx reverse proxy for your domain to port 9000. Examples taken from their site. Add this to your subdomain server configuration:

    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://localhost:9000;
    }
    

    https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/

  • aarohaaroh Member
    edited December 2020

    I use nginxs proxy manager life saver
    https://nginxproxymanager.com/

  • ninja1337ninja1337 Member
    edited December 2020

    For lighttpd

    server.modules += "mod_proxy",
    ...
    
    $HTTP["host"] == "subdomain.example.com" {
      setenv.add-response-header += (
        "X-Custom-Header" => "Whatever you want",
        "X-Requirements" => "But then you need mod_setenv",
       )
      proxy.server = ( "/" =>
        (( "host" => "127.0.0.1", "port" => 8080 ))
      )
    }
    
  • @chocolateshirt said:
    Use nginx reverse proxy for your domain to port 9000. Examples taken from their site. Add this to your subdomain server configuration:

    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://localhost:9000;
    }
    

    https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/

    It doesn't work for main page but for other page it works.

    @aaroh said:
    I use nginxs proxy manager life saver
    https://nginxproxymanager.com/

    Is it a docker based program?

    Gonna look after it.

  • @Fritz said:

    @aaroh said:
    I use nginxs proxy manager life saver
    https://nginxproxymanager.com/

    Is it a docker based program?

    Gonna look after it.

    Yes, it's based on docker and it's quite awesome. Recommend as well.

  • @JasonM said: If you are using Cloudflare (free) there's a one-click app in their store. It's free to use to route subdomain to port its called Portzilla.

  • @aaroh said:
    I use nginxs proxy manager life saver
    https://nginxproxymanager.com/

    Saving for future use.

    For lightweight reverse proxy needs, I typically have used https-portal (https://github.com/SteveLTN/https-portal). Configure the proxy map within the docker-compose yaml.

    Other implementations I have seen ... linuxserver's SWAG can do the job as well

  • Dear @Fritz!
    What you want to achieve is a bit unclear to me, but since you asked for a subdomain solution specifically, I would like to let you know that the domain name system has an SRV record type. With the SRV records you may point a subdomain to a specific port, regardless of the protocol.

  • @notmagenta said:
    Dear @Fritz!
    What you want to achieve is a bit unclear to me, but since you asked for a subdomain solution specifically, I would like to let you know that the domain name system has an SRV record type. With the SRV records you may point a subdomain to a specific port, regardless of the protocol.

    That's for service discovery. My impression is that's not what is being sought here.

  • @aaroh said:
    I use nginxs proxy manager life saver
    https://nginxproxymanager.com/

    This is cool, life saver. :smile:

  • @ddhhz said:

    @Fritz said:

    @aaroh said:
    I use nginxs proxy manager life saver
    https://nginxproxymanager.com/

    Is it a docker based program?

    Gonna look after it.

    Yes, it's based on docker and it's quite awesome. Recommend as well.

    Indeed it is running very good. Small memory footprint.

  • @saibal said:

    @JasonM said: If you are using Cloudflare (free) there's a one-click app in their store. It's free to use to route subdomain to port its called Portzilla.

    It should be free, I have tried it.

    Try to add it from Cloudflare Dashboard.

  • @notmagenta said:
    Dear @Fritz!
    What you want to achieve is a bit unclear to me, but since you asked for a subdomain solution specifically, I would like to let you know that the domain name system has an SRV record type. With the SRV records you may point a subdomain to a specific port, regardless of the protocol.

    I am referring for reverse proxy to Port.

    I stick to my existing nginx installation for now.

  • @tetech said:

    @notmagenta said:
    Dear @Fritz!
    What you want to achieve is a bit unclear to me, but since you asked for a subdomain solution specifically, I would like to let you know that the domain name system has an SRV record type. With the SRV records you may point a subdomain to a specific port, regardless of the protocol.

    That's for service discovery. My impression is that's not what is being sought here.

    That's right my friend.

  • FritzFritz Veteran
    edited December 2020

    @chocolateshirt said:
    Use nginx reverse proxy for your domain to port 9000. Examples taken from their site. Add this to your subdomain server configuration:

    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://localhost:9000;
    }
    

    https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/

    Thanks bro.

    Here is my final configuration if anyone interested :

    #PROXY-START/
    location ~* \.(php|jsp|cgi|asp|aspx)$
    {
        proxy_pass http://IP:PORT;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
    }
    location /
    {
        proxy_pass http://IP:PORT;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
    
        #Persistent connection related configuration
    
        add_header X-Cache $upstream_cache_status;
    
        #Set Nginx Cache
    
    
        proxy_ignore_headers Set-Cookie Cache-Control expires;
        proxy_cache cache_one;
        proxy_cache_key $host$uri$is_args$args;
        proxy_cache_valid 200 304 301 302 5m;
        expires 12h;
    }
    
    #PROXY-END/
    
    

    Quite good as I don't need to use docker.

  • By making changes in virtualhost port configuration

  • @aaroh said:
    I use nginxs proxy manager life saver
    https://nginxproxymanager.com/

    thanks, i need this for my project.

  • I am experimenting with non as well

  • @aaroh said:
    I use nginxs proxy manager life saver
    https://nginxproxymanager.com/

    This is awesome. Thanks

  • You can redirect your domain to a certain port. This depends on the WebService you are using -Nginx/Apache. If you are using Nginx, you’ll need to do add a server block to your Nginx’s website config. This can be achieved by using the bellow
    location /{
    proxy_pass http://127.0.0.1:9000/;
    }

  • @Fritz said: Quite good as I don't need to use docker.

    Gets my vote. ;)

Sign In or Register to comment.