0

I have a React app deployed with Nginx in a AWS EC2 instance and it runs well when I use navigation bar to open a page.

But when I refresh a page, it says 404 not found even though it works correctly with navigation.

enter image description here

Both front-end(React) and back-end(Node) services are running in the server.

And my Nginx configuration is below.

enter image description here

hotcakedev
  • 2,194
  • 1
  • 25
  • 47
  • You need a catch all route in the back end. Like `app.get('*', function(req, res) { // copy paste the root path code here });`. Front end navigation with something like `react-router` and hitting the backend routes directly (like with a page refresh or manually entering address in the address bar and hitting enter) aren't the same thing. – Jayce444 Sep 28 '20 at 03:46
  • do you have web.config? – Eran Amarante Sep 28 '20 at 03:51
  • something similar happened to me - on Azure Web App. Look at this - https://stackoverflow.com/questions/64051157/react-js-app-routing-issue-only-after-deploying-to-azure-web-app . it is probably an app configuration issue – Jay Sep 28 '20 at 06:06
  • @EranAmarante, I am not using IIS, so it has no web.config. – hotcakedev Sep 28 '20 at 08:13

1 Answers1

0

enter image description here

This is my index.js route in Node back-end. And imported it to app.js in the root folder.

var indexRouter = require('./routes/index');

And Jade is installed, but never used. Please let me know any updates for this issue.

hotcakedev
  • 2,194
  • 1
  • 25
  • 47