A
A
Alexey Kostyukhin2022-03-31 13:12:49
Nginx
Alexey Kostyukhin, 2022-03-31 13:12:49

How to set up Nginx for React-router?

I built an application on react for the WEB, configured Nginx, everything works. But there was a problem.
When I go to the root, let's say https://site.ru/client/dev - then everything works, but when I want to go to some URL, like https://sire.ru/client/dev/post/1 then nginx returns a 404 error.
Attached is the nginx config.

server {
        listen 443 ssl;

        # Add index.php to the list if you are using PHP
#       index index.html index.htm index.nginx-debian.html;

        server_name test.ru


        client_max_body_size 20M;

#       location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
#               try_files $uri $uri/ =404;
#       }

#       location / {
#               root /var/www/site.ru
#       }

        location /cru {
                proxy_pass http://localhost:3000;
        }

        location /dev {
               proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
               proxy_set_header Host $host;

               proxy_pass http://localhost:3000;
        }

        location /client/dev {
                alias /var/www/site.ru/build;
        }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2022-03-31
@aleksey4uk

location /client/dev {
        alias /var/www/site.ru/build;
        try_files $uri /index.html =404;
}

Or
location /client/dev {
        alias /var/www/site.ru/build;
        try_files $uri /client/dev/index.html;
}

K
ky0, 2022-03-31
@ky0

Where are the encryption settings? Certificate, key, etc?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question