0

I've made a Javalin backend host that I've been starting on 0.0.0.0:7000 for a while now, but I recently began using Apache2 for the frontend content-serving. I was able to get apache set up, and it's running great, but now my backend won't start, with the error Failed to bind to 0.0.0.0/0.0.0.0:80 and then later Failed to bind to 0.0.0.0/0.0.0.0:443. How can I configure this so that both run at the same time, and I can use my backend server to handle requests to mysite.com/api/, but requests to mysite.com/ are served by apache?

LetsdothisEpic
  • 126
  • 1
  • 6

2 Answers2

2

Indeed Javalin and Apache can't listen on the same port at the same time. My suggestion will be to keep Apache running on ports 80 and 443 to handle the traffic of mysite.com, and then proxy to Javalin which listens on port 7000 for /api with the help of Apache mod_proxy. In your Apache VirtualHost configuration:

<VirtualHost *:443>
    ServerName mysite.com
    DocumentRoot /path/to/your/frontend

    # redirect requests on /api to Javalin backend
    ProxyPass /api http://127.0.0.1:7000

    # rest of configuration
</VirtualHost>
Romibuzi
  • 184
  • 7
  • Thank you for the help, I figured it would involve ProxyPass, but I'm having an issue with Javalin now, as it is still attempting to start on 0.0.0.0:80 and 0.0.0.0:443, despite configuring it with ```.start("127.0.0.1", 7000);``` – LetsdothisEpic Aug 18 '22 at 18:44
  • Edit: Nevermind, I just needed to disable SSL inside of Javalin, I'm assuming it will still be signed by Apache. However, I'm now getting 404 not founds with my requests, despite Javalin appearing to boot just fine. – LetsdothisEpic Aug 18 '22 at 18:47
  • @LetsdothisEpic - "_ now getting 404 not found_": You can ask this as a new question, to clarify the problem and show all the relevant (updated) code & config you are using. – andrewJames Aug 20 '22 at 13:29
1

You're using the SSL Plugin, if so you must configure your ports in the plugin config.

For example:

SSLPlugin plugin = new SSLPlugin(conf -> {
    conf.pemFromPath("/path/to/cert.pem", "/path/to/key.pem");
    conf.insecurePort = 80;                     
    conf.securePort = 443; 

    // additional configuration options
});

However, since you're using Apache as a reverse proxy you might not need the SSL plugin at all, since Apache can terminate your SSL connections for you. Unencrypted traffic will only be exchanged between Apache and Javalin: app diagram

Disclaimer: I am the author of the SSL plugin