2

I have a very simple js server (w/ webpack) serving a simple client-side app. My configuration file looks like this:

server {
    listen 80;

    root /home/user/project/dist;
    index index.html;

    server_name project.example.com;

    location / { 
        try_files $uri $uri/ =404;
    }
}

I have tried many combinations of try_files. I don't want it to 404 when it can't find something other than index.html (which is what it currently does). It works OK for the root (pointing the browser to project.example.com, but anything else gives a 404.

To solve this, I've tried to set try_files in many combinations, such as:

try_files $uri index.html; try_files $uri $uri/ index.html; try_files $uri /absoulute/path/to/index.html;

They either 404 everything or give a 500, which, according to nginx logs, is an infinite redirect loopback.

I don't think what I'm doing is terribly complex, but everything I've tried so far hasn't done what I want, which is to allow react-router to take care of everything by having try_files just give everything to index.html.

Any help appreciated.

1 Answer 1

1

nginx URIs contain a leading /. If the URI http://project.example.com/index.html works, then the try_files statement should look like:

try_files $uri $uri/ /index.html;

See this document for details.

Sign up to request clarification or add additional context in comments.

1 Comment

Clearly I didn't try every combination. :) Many thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.