Nuxt.js: Run "nuxt serve" under subpath (/prefix)

Created on 8 Sep 2017  路  5Comments  路  Source: nuxt/nuxt.js

Hey,

I'm trying to serve nuxt behind Caddy. This is my Caddyfile:

my.domain.com

gzip

...

proxy /prefix localhost:3000 {
    header_upstream Host {host}
    header_upstream X-Real-IP {remote}
    header_upstream X-Forwarded-For {remote}
    header_upstream X-Forwarded-Proto {scheme}
    header_upstream X-Scheme {scheme}
    header_upstream X-Script-Name /trailblazer-ui
}

However, when I navigate to my URL: my.domain.com/prefix I get an error because the server can't find the page:

screen shot 2017-09-08 at 17 17 17

So the server is working but something about the URL prefix is messing things up..

I had to install a reverse proxy fix plugin to make this work in Flask (Python framework) so I was wondering if there's is something similar I have to do here?

This question is available on Nuxt.js community (#c1444)

Most helpful comment

Hi. Did you tried adding router base to nuxt.config.js file? docs

```js
{
router: {
base: '/prefix/'
}
}

All 5 comments

Hi. Did you tried adding router base to nuxt.config.js file? docs

```js
{
router: {
base: '/prefix/'
}
}

Oh thank you - I didn't find that in the documentation!
It seems to be the setting I was looking for 馃槃

Together with relative paths to assets:

<img src="~/static/trailblazer.png">

... it's working like a charm!

Thanks so much

how do you do relative paths to assets mentioned in the nuxt.config.js like so?

    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/icon.png' },
      { rel: 'stylesheet', href: '/reset.css' }
    ],

I've just implemented this very thing but I can't for the life of me get the static paths to render correctly for SVG.

This works fine <img src="~/static/trailblazer.png"> but <svg><use xlink:href="~/static/symbols.svg#launch"></use></svg> does not.

Anyone seen this?

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

surmon-china picture surmon-china  路  3Comments

mattdharmon picture mattdharmon  路  3Comments

maicong picture maicong  路  3Comments

gary149 picture gary149  路  3Comments

vadimsg picture vadimsg  路  3Comments