Azure Web App Serving a Vite React App WIth Nginx - Stack Overflow

admin2025-04-18  1

I am hosting a react web app in the Azure Web App. My app is containerized and is getting deployed via Docker Compose:

I am using Nginx as a web server to launch this app.

For my nginx.conf, I am confused why the removing of $uri/ is causing a 404 Not Found error. I have my index.html placed within the /usr/share/nginx/html/ directory.

nginx.conf.template:

server {
  listen       80;

  location ${SUB_PATH} {
   alias /usr/share/nginx/html/;
   try_files $uri index.html;
  }
}

/etc/nginx/conf.d# cat default.conf

server {
  listen       80;


  # If SUB_PATH is "/", this becomes 'location /'
  # IF SUB_PATH is "/test/", this becomes 'location /test/'
  location /test/ {
     alias /usr/share/nginx/html/;
     try_files $uri index.html;
  }
}

If I remove the $uri/ I am getting the following error:

2025-01-29T15:09:11.861827644Z: [ERROR] 2025/01/29 15:09:11 [error] 13#13: *3 open() "/etc/nginx/htmlindex.html" failed (2: No such file or directory), client: 172.16.121.1, server: , request: "GET / HTTP/1.1", host: "custom-domain.azurewebsites"

  1. I never did set up such a path like /etc/nginx/html
  2. Why nginx doesn't search for the index.html file within /usr/share/nginx/html/?
转载请注明原文地址:http://anycun.com/QandA/1744957196a90015.html