0

I am having trouble to service two react app with nginX. However I try to call mySiteURL/admin route, it keeps showing mySiteURL Here is my config file.

location / {
    root /var/www/html/recipetube-client/build;
    try_files $uri /index.html;
}
location /admin {
    root /var/www/html/recipe-tube-admin/build;
    try_files $uri /index.html;
}

How can I change my config to be able to serve two react app on one sever.

1 Answer 1

1

Suggest to use these location {} blocks:

location / {
    alias /var/www/html/recipetube-client/build/;
}
location /admin {
    alias /var/www/html/recipe-tube-admin/build/;
}

Note the trailing / for the alias line

You may read more about the alias syntax here

The docs say you need to add a trailing / for admin but in my experience, this requires website visitors to strictly use mySiteURL/admin/ with the trailing /. If they try to access mySiteURL/admin, they'll get 404 Not Found.

I took out the / in my location /admin {} block, and mySiteURL/admin worked fine.

In summary:

location /admin/ {} -> Access mySiteURL/admin/ -> OK

location /admin/ {} -> Access mySiteURL/admin (no /) -> 404 Not Found

location /admin {} -> Access mySiteURL/admin -> OK

location /admin {} -> Access mySiteURL/admin/ -> OK

Hope this helps you!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.