Ubuntu - Redirect http/2 requests to domain and subdomain to different ports

384 views Asked by At

I am running two http/2 servers on my ubuntu server. Both should be reachable over port 443.

App A:

Runs on port 8443 and should get requests for domain.com

App B:

Runs on port 8444 and should get requests for subdomain.domain.com

Is there a simple way to do this on Ubuntu?

1

There are 1 answers

5
Barry Pollard On BEST ANSWER

Yes this is possible.

You need to run a webserver or loadbalancer listening to port 443 and forwarding requests appropriately.

In Apache for example this would be handled as follows:

Listen 443

<VirtualHost *:443>
    # This first-listed virtual host is also the default for *:443
    ServerName domain.com
    DocumentRoot "/www/domain"
    ProxyPass / h2://127.0.0.1:8443/
    ProxyPassReverse h2://127.0.0.1:8443/
</VirtualHost>

<VirtualHost *:443>
    ServerName subdomain.domain.com
    DocumentRoot "/www/otherdomain"
    ProxyPass / h2://127.0.0.1:8444/
    ProxyPassReverse h2://127.0.0.1:8444/
</VirtualHost>

Now while Apache does support HTTP/2 in both the front end client connections and the back end ProxyPass requests (with mod_proxy_http2), some other webservers/loadbalancers don't (e.g. Nginx). To be honest most of the benefits for HTTP/2 are in the client to edge. So if you prefer to use Nginx for example, you could just have Nginx support HTTP/2, and the connection from Nginx to your back end apps be plain old HTTP/1.1. At least until HTTP/2 becomes more regularly supported. See here for more discussion on this: HTTP2 with node.js behind nginx proxy