0

I have configured my local nginx server with this snippet:

   location / {
        root   html;
        index  index.html;
        try_files $uri $uri /index.html;
    }

which is inside http { server { ... } }. I also have an nginx server on Digital Ocean, and I put the above snippet in the same location (...) in the file /etc/nginx/nginx.conf. However, those changes are ignored by the server, i.e., the behavior after is the same as the behavior before (and unlike the behavior of the local server).

What am I doing wrong?

jxxcarlson
  • 223
  • 3
  • 13

2 Answers2

0

After every change you make to your nginx files (or to your website) it is important to reload nginx to apply the changes by using the following in the terminal/command line: sudo nginx -s reload

You can also run nginx -t to test nginx for any conflicts.

You can (and probably should) run them together to make it easier:

sudo nginx -t && sudo nginx -s reload
Jake
  • 1,086
  • 12
  • 38
  • Hi, I tried that, but I still get an error, e.g., http://www.knode.io/559 produces a 404 error on nginx at Digital ocean but not at http://localhost:8080. The intent is to always serve `index.html` and let the client app parse and handle the rest of the URL. – jxxcarlson Jul 31 '18 at 16:31
  • NOTE: above, it should be `$uri $uri/` – jxxcarlson Jul 31 '18 at 18:22
  • @epsilon2.7 are you running ruby on rails by any chance? Also, please post your whole nginx conf file and possibly the files from `sites-enabled` & `sites-available`. Feel free to put placeholder domain names and IP addresses to protect your privacy. – Jake Jul 31 '18 at 20:18
  • Not running rails -- Using `nginx` to serve an Elm app. It consists of two files, `index.html` and `Main.js`. I'll post the `nginx` files as soon as I figure out a way to do so. They are two big for the comments. Thanks so much!! – jxxcarlson Jul 31 '18 at 22:08
  • Here are links to the nginx files: http://noteimages.s3.amazonaws.com/uploads/nginx.conf http://noteimages.s3.amazonaws.com/uploads/sites-enabled-default http://noteimages.s3.amazonaws.com/uploads/sites-available-default – jxxcarlson Jul 31 '18 at 22:17
  • If you're using Let's Encrypt, please take a look at [the answer to my question](https://stackoverflow.com/questions/51343190/nginx-with-lets-encrypt-welcome-to-nginx-instead-of-rails-app), I think it will help you if you are. – Jake Aug 01 '18 at 12:09
0

It is necessary to make the change

try_files $uri $uri/ =404;

to

try_files $uri $uri/ /index.html;

in two places in /etc/nginx/sites-available also.

jxxcarlson
  • 223
  • 3
  • 13