How to run a service on subdomain instead of port on AlmaLinux with Cpanel?

197 views Asked by At

I have a version of keycloak running on my AlmaLinux server. This service runs on port 8080. I can access it using <SERVER-IP>:8080. I however, want to access the service using mysubdomain.mymaindomain.com. This way, the user is not confronted with port-numbers, and I suppose using autoSSL is easier (I cannot get it to work on a different port).

I tried multiple things. The first (I know, very sketchy) was rerouting using htaccess. I made a rewrite condition that looped to localhost:8080. At first glance this worked, but redirects did not work. I suppose this is, since the service thinks it runs on 'localhost:8080' (what it of course does), and thus redirects (on the browser side) to localhost:8080/home for example.

The second thing I tried was adding this code to the virtualhost config file. I added this using the WHM environment in the server configuration > apache configuration > include editor. There I tried both 'Pre Virtual Host Include' and 'Post Virtual Host Include' (Originating from here).

<VirtualHost *:80>
    DocumentRoot "/public_html/keycloak_public"
    ServerName mysubdomain.mymaindomain.com

    # Other directives here
</VirtualHost>

That did not work, I found out I had to use a proxy. So I appended the following code behind the former part. (Originating from here).

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName mysubdomain.mymaindomain.com
    ProxyPreserveHost On

    # setup the proxy
    <Proxy *>
        Order allow,deny
        Allow from all
    </Proxy>
    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/
</VirtualHost>

However, when I go to mysubdomain.mymaindomain.com this still loads the empty directory, instead of the equivalent of :8080.

According to the above mentioned thread, I have to enable proxy somehow, but I did not find a way to do so in Cpanel, so I kind of assumed it was enabled (I'm sorry). Can that be the problem, or should I look somewhere else in order to fix this problem?

1

There are 1 answers

0
Tijs Klaren On

The solution turned out to be replacing the * with the server-ip!