Не запускается ReactJS на Apache (Ubuntu)
На своём пк я сбилдил приложение ReactJs командой npm run build, затем мне высветилось сообщение об успешном билде и такое сообщение:
You may serve it with a static server:
npm install -g serve
serve -s build
Если я пишу эти команды, то сбилженное приложение прекрасно запускается у меня на компьютере, но когда я перекидываю этот билд на VDS, под управлением Ubuntu и за сторону сервера отвечает Apache, то при попытке загрузить сайт в консоль сайта пишется ошибка:
main.d74030ae.chunk.css:1 Failed to load resource: the server responded with a status of 404 (Not Found)
2.267f33d3.chunk.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
main.84a11725.chunk.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
2.267f33d3.chunk.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
main.84a11725.chunk.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
favicon.ico:1 Failed to load resource: the server responded with a status of 404 (Not Found)
manifest.json:1 Failed to load resource: the server responded with a status of 404 (Not Found)
manifest.json:1 Manifest: Line: 1, column: 1, Syntax error.
manifest.json:1 Failed to load resource: the server responded with a status of 404 (Not Found)
main.d74030ae.chunk.css:1 Failed to load resource: the server responded with a status of 404 (Not Found)
и сайт полностью белый
Что делать?
Ответы (1 шт):
При использовании create react app по умолчанию приложение рассчитано на запуск из корневой папки. Для запуска из другой папки нужно добавить в package.json параметр homepage:
"homepage": "http://mywebsite.com/relativepath",
https://create-react-app.dev/docs/deployment/#building-for-relative-paths