Thursday, April 6, 2023

Run React Project With Subdirectory URL

In this Blog we are going to execute react project with the sub-directory URL rather than port or separate domain.



Ex: http://example.com/frontend or http://example.com/backend


1) Add Below Line with Sub-directory Name In package.json file


  "homepage": "/frontend",


2) Then use below commands

  • npm install
  • npm run build
  • pm2 start server.js


3) Add below content in Apache Virtualhost File

ProxyPreserveHost On
ProxyPass /frontend http://127.0.0.1:3009/
ProxyPassReverse /frontend http://127.0.0.1:3009/

4) Make Sure below apache mode enabled if not then use below one

  • sudo a2enmod proxy
  • sudo a2enmod proxy_http
  • sudo a2enmod proxy_balancer
  • sudo a2enmod lbmethod_byrequests
  • sudo systemctl restart apache2


5) Finally ! Now You Can Access Sub-Directory URL's

https://example.com/frontend

Or

https://example.com/backend

No comments:

Post a Comment

testing