简体   繁体   中英

404 NOT found ngnix error when refrehsing page

I am getting an error 404 not found ngnix when I refresh my application. My application seems to work fine if i first reboot and is able to route to different pages untill i refresh my page directly.

This seems like a ngnix issue since it works fine when I run local host after building the front end. I've notied other people had issues and they were able to solve their issue buy adding try_file $uri /index.html but I already put that ahead of time and still getting this problem

location / {
                root /boost/server/build;
                index index.html
                try_file $uri /index.html;
        }

    location /api/ {
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_set_header X-NginX-Proxy true;
                proxy_pass http://my_public_ip;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;

        }

Any help would be appreciated

You should use semicolon after index.html. Like this

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

or this way

location / {
root /boost/server/build;
set $fallback_file /index.html;
if ($http_accept !~ text/html) {
    set $fallback_file /null;
}
try_files $uri $fallback_file;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM