1 | initial version |
To set up Nuxt 3 to operate behind a reverse proxy, follow these steps:
Configure the reverse proxy to forward requests to the Nuxt 3 server. This can typically be done by adding a proxy pass directive in the reverse proxy configuration.
In the Nuxt 3 server configuration, set the base URL. The base URL specifies the URL path that Nuxt will operate under. You can set the base URL using the "router" property in the "nuxt.config.js" file, like so:
export default {
router: {
base: '/my-app/'
}
}
export default {
server: {
trustProxy: true
}
}
export default {
router: {
middleware: 'routePrefix'
}
}
// routePrefix.js middleware
export default function ({ route }) {
if (process.server) {
const prefix = '/my-app'
route.path = route.path.replace(prefix, '')
}
}
export default {
server: {
https: true
}
}
By following these steps, you should be able to run your Nuxt 3 application behind a reverse proxy.