1

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...

Calix
  • 15
  • 3
  • 1
    Check [404 when trying to enter a react app route](https://stackoverflow.com/a/62050700/2873538) and then try [How to redirect to index.html for error 404?](https://stackoverflow.com/a/67312778/2873538) – Ajeet Shah May 07 '21 at 09:01
  • @AjeetShah thanks for answer. It looks promising, but the problem is that i cannot redirect to index.html, due to proxy. Networking shows that I don't have index.html file, it's called differently. It's called like server name, in example: server.domain.com, instead of index.html. So doing try_files to /index.html throws 500. (redirection loop? idk) – Calix May 07 '21 at 09:24
  • 1
    You are using nginx proxy. So, I think that you should do the above (404 --> index.html) at the server serving your React Build i.e. the server handling `http://somehost:10010/`. – Ajeet Shah May 07 '21 at 09:31
  • 1
    Not sure but you may also need to add more locations and do proxy pass. Something in [this](https://serverfault.com/q/849989/362305) direction. – Ajeet Shah May 07 '21 at 09:35

1 Answers1

0

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.

Calix
  • 15
  • 3