I have a React app built using Vite that I intent to serve on Nginx at www.example.com/myapp
I've set basename
in the React Router
to /myapp
and have set the "homepage": "/myapp"
in package.json
and it works great when I run vite dev server - the site is correctly scoped and served at localhost:5173/myapp
.
However after running vite build
and copying to my NGinx server, the linking doesn't work. Here is the location config which is based off this answer ...
location ^~ /myapp {
// ...
index index.html;
alias /home/ubuntu/myrepo/dist;
try_files $uri $uri/ /myapp/index.html =404;
}
Weirdly, in the logs it does seem to be resolving to another root, /usr/share/nginx/html/myapp/index.html
when there is not reference to /usr/share/nginx/html
in any of my config.
It doesn't work though. I can only guess it is becuase create-react-app
does something different to vite build
?