Reputation: 1797
I have 3 apps: 1 nodejs and 2 react apps. My nginx.conf looks like this:
#node-app is running on port 3001
upstream api {
server localhost:3001;
}
server {
listen 80;
listen [::]:80;
server_name _;
index index.html index.htm;
location /api {
rewrite /api /$1 break;
proxy_pass http://api;
}
#the first react app
location /admin {
root /home/ec2-user/admin/build;
try_files $1 index.html;
}
#the second react app
location / {
root /home/ec2-user/client/build;
try_files $uri /index.html;
}
What happens is that I can go to the second react app. But when I go to the admin-page I got an nginx error:
The page you are looking for is not found.
I also have tried to declare the admin this way:
location /admin/(.*) {
root /home/ec2-user/admin/build;
try_files $1 index.html;
}
But then the page does not display anything. I suspect that the app number 2 takes over, but as there is no route to "admin" it shows an empty page.
Upvotes: 0
Views: 71
Reputation: 341
Please add
these rule in nginx
#First app
location ^~ /admin/ {
if (!-e $request_filename){
rewrite ^(.*)$ /index.html break;
}
root /home/ec2-user/admin/build;
}
###Second app
location ^~ /admin-page/ {
if (!-e $request_filename){
rewrite ^(.*)$ /index.html break;
}
root /home/ec2-user/client/build;
}
Upvotes: 1