D
Dokploy2mo ago
Daniel

404 Not Found when refreshing SPA React Vite app

Hi, guys. I just deployed my Vite React app following the docs from the website (https://docs.dokploy.com/docs/core/vite-react). It worked fine but when i refresh or tried to access to a route of the SPA app it will throw 404 Not Found as shown in the image. I know that i need to do a redirect but i'm not sure where exactly and what i need to put. I'm using self-hosted Dokploy inside a VPS.
Welcome to Dokploy | Dokploy
Dokploy is a open source alternative to Heroku, Vercel, and Netlify.
No description
2 Replies
Daryl
Daryl5w ago
Hi! I encountered this issue yesterday, and adding my own nginx config was necessary: * You have to add a File mount (<your_project> -> Advanced -> Volumes -> Add volume -> File mount). * The content can be the following:
server {
location / {
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ /index.html;
}

# Handle 404 errors
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
internal;
}

# Handle server errors (50x)
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
internal;
}
}
server {
location / {
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ /index.html;
}

# Handle 404 errors
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
internal;
}

# Handle server errors (50x)
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
internal;
}
}
* The File path should be: default.conf * The Mount path should be: /etc/nginx/conf.d/default.conf Note: I took the content from here. I hope that it also solves your problem.
Flain
Flain4w ago
it worked for me! Thank you very much

Did you find this page helpful?