cha1ra
cha1ra

Reputation: 23

Nuxt.js is not working when I change Nginx location

Environment

Issue

I'm trying to deploy nuxt.js (SSR mode) on AWS using ninx reverse proxy feature.

I configure /etc/nginx/sites-available/hoge.com file as below,
same as Official FAQ: https://nuxtjs.org/faq/nginx-proxy/

map $sent_http_content_type $expires {
    "text/html"                 epoch;
    "text/html; charset=utf-8"  epoch;
    default                     off;
}

server {
    listen          80;

    gzip            on;
    gzip_types      text/plain application/xml text/css application/javascript;
    gzip_min_length 1000;

    location / {
        expires $expires;

        proxy_redirect                      off;
        proxy_set_header Host               $host;
        proxy_set_header X-Real-IP          $remote_addr;
        proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto  $scheme;
        proxy_read_timeout          1m;
        proxy_connect_timeout       1m;
        proxy_pass                          http://127.0.0.1:3000;
    }
}

If I access to http://hoge.com, it works.
BUT after I change location path below, nuxt.js cannnot render itself.

When rewrite hoge.com file ...

server {
    ...

-    location / {
+    location /fuga/ {
      ...
    }
}

and then access http://hoge.com/fuga/, It's not working

Error Scrreen

console.log

GET http://hoge.com/_nuxt/a7cb158397e68912ff29.js net::ERR_ABORTED 404 (Not Found)
(index):569 GET http://hoge.com/_nuxt/img/7f93e7b.png 404 (Not Found)
(index):567 GET http://hoge.com/_nuxt/img/37def1e.png 404 (Not Found)
6(index):569 GET http://hoge.com/_nuxt/img/d9ced4d.png 404 (Not Found)
(index):1 Unchecked runtime.lastError: The message port closed before a response was received.
favicon.ico:1 GET http://hoge.com/favicon.ico 404 (Not Found)

It seems that resource file path refers still previous URL.
But I have no idea how to fix it.

Upvotes: 2

Views: 3908

Answers (1)

Aldarund
Aldarund

Reputation: 17621

You need to set router base

export default {
  router: {
    base: '/fuga/'
  }
}

Upvotes: 4

Related Questions