I want to deploy two React applications on a single Nginx server and domain. When I configure my Nginx server to serve the first application at the root path ("/"), it works correctly.
However, when I configure it to serve the second application at the path "/biro-cat", it only shows the background image. What could be wrong?
server {
listen 80;
server_name ec2-18-207-215-29.compute-1.amazonaws.com;
location /api/ {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
location /biro-cat {
alias /var/www/biro-cat;
try_files $uri /biro-cat/index.html;
}
location / {
root /var/www/take-me;
try_files $uri /uri /index.html;
}
}
2
Answers
In the second app, make sure you configured two places
In
package.json
, add this line:In your router, edit it like this:
It should works as you expected
If mikenlanggio’s doesn’t work, then I will recommend you to change basename="/" and PUBLIC_URL=/biro-cat.
After building package, check the dist || build directory’s index.html, that might have [path(biro-cat)]/static/js/[filename].js in the script tag.
Also, you should check the index.html at the network tab in dev mode which request proper index.html.
By checking the index.html on network tab, it have to contain the path that you just defined likes [path(biro-cat)]/static/js/[filename].js
Here is the Example :
there is no other settings, homepage in package.json, basename in router ..etc