How to use Apache to serve Django server and React client?

Viewed 1988

I'm trying to configure Apache2 to serve Django for backend APIs (/api/), and React app for client side JS (/).

I want the root path to load the React app (e.g. www.example.com/).

I'm having a hard time. If I Alias/Documentroot the / to React's /build directory, then Apache stops serving Django. And conversely when I remove the Alias/Documentroot, then Django serves fine but React doesn't. How could I do this?

Here's my httpd.conf file:

```

DocumentRoot /home/ubuntu/project/webapp/build/
Alias / /home/ubuntu/project/webapp/build/
<Directory /home/ubuntu/project/webapp/build>
    Require all granted
</Directory>

Alias /static /home/ubuntu/project/webapp/build/static
<Directory /home/ubuntu/project/webapp/build/static>
    Require all granted
</Directory>

WSGIDaemonProcess server python-home=/home/ubuntu/python3.5/ python-path=/home/ubuntu/project/server
WSGIProcessGroup server
WSGIScriptAlias /admin /home/ubuntu/project/server/server/wsgi.py

<Directory /home/ubuntu/project/server/server>
<Files wsgi.py>
    Require all granted
</Files>
</Directory>

```

3 Answers

Firstly, delete the DocumentRoot and the first Alias and Directory that lead to the build folder. Those are not needed. You only need the Alias and Directory that leads to the static folder inside build.

You will also need to make sure that Django knows where to find your React static files. I have already configured an app using this technique. Please see my post about this exact topic here

Related