0

I'm having an issue with nginx serving my static website files (CSS and JS) when you navigate to any route with more than one slash. For example, example.com/test works, but example.com/test/test will try and load the css/js from example.com/test/{.css|.js} instead of the root directory.

For context, I am using React and ReactRouter on this website.

nginx config

server {
    listen 80;

    server_name example.com;

    root /var/www/example.com;
    index index.html;

    rewrite ^.*$ /index.html;

    location / {
        try_files $uri /index.html;
    }
}
2
  • Where do you specify the name of the CSS/JS file. You need to put a / in front. Commented Sep 18, 2020 at 15:34
  • Yep, that was the problem. I found the solution here: stackoverflow.com/questions/43191569/… Commented Sep 18, 2020 at 15:45

1 Answer 1

1

Turns out it was html-webpack-plugin not putting a / in front of the assets because publicPath was not set in the output.

See answer here: html-webpack-plugin and webpack 2: no starting slash '/'

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

Comments

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.