Ad

How Configure Nginx For Prerender React App?

- 1 answer

I've got React app.

It works well on local machine (app + prerender-spa-plugin). I run it with command http-server into ./build package

However thing go wrong on server - it acts like if I launch it with serve-s command.

There is docker with nginx image on server.

I tried to reconfigure nginx the way that it uses different index.html for different URLs, but fail again

Do the problem with routing to directories that keeps static images?

How it could be resolved? or where I could find information about it?

Ad

Answer

I decided it. My config

location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
        }

From official documentation:"It is possible to check directory’s existence by specifying a slash at the end of a name, e.g. “$uri/”."

https://i.stack.imgur.com/PusBE.png

Ad
source: stackoverflow.com
Ad