【发布时间】:2019-08-27 04:52:10
【问题描述】:
环境
- Ubuntu 18.04.2 LTS
- nginx 版本:nginx/1.14.0 (Ubuntu)
- @nuxt/cli v2.4.5
问题
我正在尝试使用 ninx 反向代理功能在 AWS 上部署 nuxt.js(SSR 模式)。
我配置/etc/nginx/sites-available/hoge.com文件如下,
同官方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;
}
}
如果我访问http://hoge.com,它可以工作。
但是在我更改下面的位置路径后,nuxt.js 无法自行渲染。
重写hoge.com文件时...
server {
...
- location / {
+ location /fuga/ {
...
}
}
然后访问http://hoge.com/fuga/,不行
控制台日志
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)
似乎资源文件路径仍然指向以前的 URL。
但我不知道如何解决它。
【问题讨论】: