How to configure Apache server running on Ubuntu 20.04 to Serve Two Different Projects on Different Port?

I am building a web application with React as frontend and Laravel as backend. Both Laravel and React are built on separate project and I want both of these projects to deploy on the same server instance.

So for that, I put React project inside /var/www/react directory and Laravel project in /var/www/laravel directory.

So when the incoming request has the url, the request will point to /var/www/react directory. When request has url with some prefix for example, the request will point to /var/www/laravel directory.

For this purpose, I followed this tutorial and setup two virtual host. Both of these two virtual hosts points to same server but has different DocumentRoot for different port.

So first virtual host has /var/www/react as DocumentRoot which listen on port 80 while another virtual host has /var/www/laravel as DocumentRoot which listen on port 8080.

I have added the port 8080 in /etc/apache2/ports.conf file for it to listen.

After all this setup, when I goto my url, it actually loads the files from /var/www/react directory but when I try to open same url by specifying the port for example, it does not work.

Even the url with port 8080 does not work.

I get the following error

This site can’t provide a secure connection. sent an invalid response. ERR_SSL_PROTOCOL_ERROR

Here is my code


ServerAdmin webmaster@localhost


ServerAlias *

DocumentRoot /var/www/laravel


ServerAdmin webmaster@localhost


ServerAlias *

DocumentRoot /var/www/react


Listen 80

<IfModule ssl_module> Listen 8080 </IfModule>

<IfModule mod_gnutls.c> Listen 8080 </IfModule>

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
June 6, 2022

Hi there,

Indeed as already mentioned you can do that with different Apache Virtual Hosts.

For more information, you could also refer to the following tutorial:

Let me know if you have any questions!



Heyy @DriftingLapisDolphin,

You have multiple domains going to the same IP and also want to serve multiple ports. The example below illustrates that the name-matching takes place after the best matching IP address and port combination is determined.

Listen 80
Listen 8080

    DocumentRoot "/www/domain-80"

    DocumentRoot "/www/domain-8080"

Hope that helps,

-Sergio Turpín

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up