The original post: /r/nginx by /u/TryinMahBest2Success on 2024-09-06 20:46:15.

So I’m serving a react application on a nginx server under the /game path.

Here’s my location block for it.

This did not work, my React application correctly served the index.html but proceeded to not find the CSS and JS files which should have been served by this location block.

location /game/ {
    root /var/www/html/build;
    try_files $uri $uri/ /index.html;
}

So this new solution.

location /game/static/js {
    alias /var/www/html/build/static/js;
    try_files $uri $uri/ /index.html;
}
location /game/static/css {
    alias /var/www/html/build/static/css;
    try_files $uri $uri/ /index.html;
}

This worked, but why? I have to assume $uri is at fault here. As you can see, I had to write the entire file path in alias, that’s supposed to be $uri’s own job. Which clearly it didnt work.

Anyone have any ideas what happened? Thanks.