React-router and nginx
Here are my solutions
simple trying:
location / {
root /var/www/mysite;
try_files $uri /index.html;
}
no more trying for non-html types:
location / {
root /var/www/mysite;
set $fallback_file /index.html;
if ($http_accept !~ text/html) {
set $fallback_file /null;
}
try_files $uri $fallback_file;
}
no more trying for non-html types and directory (making try_files
compatible with index
and/or autoindex
):
location / {
root /var/www/mysite;
index index.html;
autoindex on;
set $fallback_file /index.html;
if ($http_accept !~ text/html) {
set $fallback_file /null;
}
if ($uri ~ /$) {
set $fallback_file /null;
}
try_files $uri $fallback_file;
}
The location block in your nginx config should be:
location / {
try_files $uri /index.html;
}
The problem is that requests to the index.html file work, but you're not currently telling nginx to forward other requests to the index.html file too.