Does Nuxt have to be at the root when deployed?
So I have nuxt as a static site, however I'm reading said files from .output/public/index.html, whenever I launch it, it says 404 not found because its trying to use the URL bar as the current route, is there a way to circumvent this? I need this deployed in a subfolder and not on the root
3 Replies
Hi @Gobbo. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the knowledge sources provided, I can answer your question about deploying Nuxt in a subfolder rather than at the root.
Nuxt does not have to be deployed at the root of your server. You can deploy it in a subfolder, but you need to make some configuration changes to ensure it works correctly. Here's how you can address this:
1. In your
nuxt.config.js
file, you need to set the app.baseURL
to your subdirectory. For example:
This tells Nuxt that your application is located in the "/app" subdirectory.
2. If you're using Apache as your web server, you'll need to configure your proxy settings correctly. Here's an example of how to set it up:
This configuration tells Apache to proxy requests for "/app" to your Nuxt application running on localhost:8080.
Stack Overflow - Nuxt 3 Production in Apache2 with subdirectory (https://stackoverflow.com/questions/77549265) provides more detailed information on this setup.
It's important to note that you shouldn't try to run a Nuxt application by directly opening the index.html
file from the file system. As mentioned in another Stack Overflow post (https://stackoverflow.com/questions/78448554), Nuxt is an isomorphic app and requires a server to properly manage the state.
If you're generating a static site with Nuxt, you should use the nuxi generate
command to build your site, and then serve the generated files from a web server. You can test it locally using a simple static file server like npx serve .output/public
.
Remember, the exact configuration might vary depending on your specific setup and deployment environment. If you're still encountering issues, you may need to provide more details about your specific deployment setup for a more tailored solution.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@544168042066608139> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Issue is, I can't use /app baseURL because I need relative imports, as it tries to import from the root /_nuxt and not ./_nuxt :(