Can someone please help on what the issue is here.
I have a React web app hosted on Azure Web App. It has been deployed successful.
My problem is, if, for example, I go to the site on myweb.azurewebsites.net
it loads well. And if I click on a button like the "signin" button it redirects me to myweb.azurewebsites.net/signin
.
However, if I manually type in myweb.azurewebsites.net/signin
into the browser, it gives an "Nginx not found" error.
Can someone help on what the issue is. I suspects it's between Azure and/or Nginx.
CodePudding user response:
Nginx not found 404 error means Nginx can’t find the resources your web browser asks for.
- Check web root directory exists on your server.
- Make sure your website files are stored in the correct directory.
To resolve "Nginx not found 404 error", please find below workarounds if helpful:
The most likely issue is that you're not telling Nginx to forward other requests to the /index.html of your application, which makes it so your other pages can't be loaded directly and display a 404 error. To fix this, you'll need to make a small change to your Nginx configuration files.
Make sure your nginx.conf
file as shown below:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
location / {
root /home/user_name/Documents/your_proj; # You need to provide here the path of your "index.html" file
index index.html index.htm;
}
}
If Workaround1 does not work, try changing the location segment
as below
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index.html break;
}
}
Configure the startup command on "Settings > General settings > Startup Command". Change the path to your build path.
To redirect all queries, use the --spa
option:
pm2 serve /home/site/wwwroot/client/build --no-daemon --spa
In the nginx.conf
file, try commenting-out the disable_symlinks on
line or changing it to disable_symlinks off
.
CodePudding user response:
I discovered that I didn't add an Nginx conf file and copy it into the Nginx Docker container. When I did that, it works fine.