this post was submitted on 06 Sep 2024
1 points (100.0% liked)

nginx

4 readers
1 users here now

The nginx community on Reddit. Reddit gives you the best of the internet in one place.

founded 1 year ago
MODERATORS
 
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.

no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here