John Davidson

php - Apache proxy to reactjs page


I have 2 websites php and reactjs

  1. php site running on http://localhost

  2. react site running on http://localhost:3000

I'd like to access http://localhost:3000/funds page when user visit URL http://localhost/funds. I tried with apache proxy but it is showing blank react site as images and css missing on path. Any other suggestion to achieve this, Thanks.

ProxyPass /funds http://localhost:3000/funds
ProxyPassReverse /funds http://localhost:3000/funds

My Answer:
One possible solution is to use a reverse proxy in your Apache configuration to serve the ReactJS site. Here's an example configuration that you can add to your Apache virtual host file:

ServerName localhost

ProxyPass /funds http://localhost:3000/funds
ProxyPassReverse /funds http://localhost:3000/funds

ProxyPassReverse /
ProxyPreserveHost On
ProxyPassReverseCookieDomain localhost localhost
ProxyPassReverseCookiePath / /

This configuration sets up a reverse proxy for the `/funds` path to the ReactJS site running on `http://localhost:3000/funds`. The `` block ensures that the proxy settings are applied correctly for the `/funds` path.

Make sure to restart Apache after making these changes for them to take effect. This should allow you to access the ReactJS site at `http://localhost/funds` with the correct images and CSS paths.

Rate this post

3 of 5 based on 5028 votes


© 2024 - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us