Search code examples
reactjsnginxreverse-proxyreact-router-dom

nginx + reverse proxy + react router - routing do not work


I'm totally lame with nginx and configurations, so I would like to ask you for help.

Currently I have this config:

server { 
  listen 80; 
  server_name domain.com; 

  location / {
    proxy_pass http://somehost:10010/;
    proxy_http_version 1.1;
  }
}

Running Create React App with react-router.

Current behavior of the website: When running domain.com, it opens homepage correctly, application works.

When trying to run domain.com/some-route (i have react routing configured properly), it shows nginx 404 page.

How can I redirect any route to main domain, but keep the domain.com/some-route in URL?

I tried try_files, but it does not work for me...


Solution

  • Answer to my question is simplier that I would thought... I had two nginx'es on my instance:

    • One on the server
    • One created by docker inside a container

    I had to create config in build, and then move it into container using docker.

    Everything works fine.