this post was submitted on 05 Jul 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/konmas on 2024-07-05 12:00:36.

If I have the following nginx config:

server { 
listen 80; server_name testsite.local;

location =/ { root /var/www/html/TEST/public/; 
try_files $uri $uri/ /test.html; }

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

location /api { alias /var/www/html/TEST/API/; 
try_files $uri /index.php$is_args$args; }

location ~ /.(?!well-known).* { deny all; }

location ~ /index.php(/|$) { fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; 
fastcgi_split_path_info .+.php(/.*)$; 
include fastcgi_params; 
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; 
fastcgi_param DOCUMENT_ROOT $realpath_root; internal; 
} 
}

What I am trying to do is when you go to testsite.local it loads that static html file (test.html) and then when you navigate away to any other / it will load the react APP (testsite.local/home - testsite.local/login. - etc)

With the above config, it always seems to skip the "location =/" block and go right into the "location /" - not sure where i am going wrong? Thank you!

If I modify the above to this:

location =/GETME { root /var/www/html/TEST/public/; 
try_files $uri $uri/ /test.html; }

and then go to to testsite.local/GETME it works as expected, but I want it to go to it at testsite.local and then everywhere outside of that load the react app.

Thanks for the help!

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