I thank anyone who can give me a hand!
Basically, I have a WordPress site created with AWS Lightsail. So, I have an Apache server that exposes the WordPress site on my public address.
On a specific path, I would like to expose an application, for example, on the path TEST PUBLIC_ADDRESS/TEST, I would like to access the application.
The application is a React project available on localhost:3000 via a Next server. The application works correctly on localhost:3000, and as mentioned, I would like to first expose this application on PUBLIC_ADDRESS/TEST. How can I do it? I tried creating a virtual host first, then opening ports, etc. but to no avail.
Thank you in advance.
I tried creating a virtual host first, then opening ports, etc. but to no avail.
3
Answers
@grekier Hello, thank you for your help! Yes, there were already various virtual hosts existing. I added the commands you suggested to the virtual host used by the WordPress site (I added them at the end).
But it didn't work. I think I need to try the other alternative you suggested, which is to expose my application first on localhost:3000/test. I will update you, thank you for your help.
I do not know the setup for the WordPress Lightsail so you might need to create a VirtualHost but it might already exist so check it out.
Usual places are
/etc/apache2/conf
where you could find anhttpd.conf
file. From there it can point to another multitude of files. As it is a Debian based image, I guess you would have anapache2.conf
and a sites-enabled folder with your different VirtualHostsNow, when you have identified where you want to add the configuration to proxy to Next. You can just add:
inside the VirtualHost of your choice. This will map
/test
to localhost:3000The VirtualHost might be a new one you create with the IP or an existing one with a name if that is what you wish.
There are a couple of things to be aware of:
I believe there are other ways to achieve this but be aware that mixing path is a mess…
N.B: Also a side note on LightSail. If you try to configure a VirtualHost with the public IP and it doesn’t work, try with the private one. I think there is something funny on how routing/DNS is done in LightSail…
To accomplish this goal, you can simply follow one of the solutions provided below.
1. Configure and update your Apache Virtual Host :
Edit your Apache configuration file (usually located at
/etc/apache2/sites-available/000-default.conf
or similar) and add aProxyPass
directive to proxy requests to the React application.2. Configure React Application and
Ensure your React application is configured to run on the correct host and port. In your React application’s
package.json
, set thehomepage
property to/TEST
.if your React application is using React Router, make sure the
<BrowserRouter>
component is configured to use thebasename
prop set to/TEST
.3. Restart the Apache:
Now, when you access
http://yourdomain.com/TEST
, Apache will proxy the requests to your React application running onlocalhost:3000
. Ensure your React application is running in the background.