[英]How to make Nuxt generated static spa files in dist hosted on AWS S3
How to host Nuxt Static web app in AWS S3?如何在 AWS S3 中托管 Nuxt Static web 应用程序?
Firstly, I have tried and known how to generate static static SPA files in./dist by calling nuxt generate
.首先,我已经尝试并知道如何通过调用nuxt generate
在./dist 中生成 static static SPA 文件。
Secondly, AWS S3 supports static web hosting, but it seems that the site have to be accessed by visiting the 'index.html' in that bucket.其次,AWS S3 支持 static web 托管,但似乎必须通过访问该存储桶中的“index.html”来访问该站点。
So, I came to this problem, for example, I got a bucket 'demo2020', and I upload Nuxt/Vue files in the./dist into that.所以,我就来了这个问题,例如,我有一个桶'demo2020',然后我将./dist中的Nuxt/Vue文件上传到其中。 I have also set the bucket and files in in public.我还公开设置了存储桶和文件。 After these, I can visit images in the demo2020 bucket, but the index.html, ie, http://demo2020.s3-us-west-1.amazonaws.com/index.html could not be visited.在这些之后,我可以访问demo2020存储桶中的图像,但是不能访问index.html,即http://demo2020.s3-us-west-1.amazonaws.com/index.ZFC336FDC70D22C7A28 。
An error page, 200.html was returned, saying:错误页面 200.html 被返回,说:
This page could not be found找不到此页面
Back to the home page返回首页
This normally works on standard web server, for example, nginx or http-server/express etc. But no luck on AWS S3 yet.这通常适用于标准 web 服务器,例如 nginx 或 http-server/express 等。但在 AWS S3 上还没有运气。
This is not problem of aws s3, on the localhost, if index.html from nuxt, same error page.这不是 aws s3 的问题,在本地主机上,如果 index.html 来自 nuxt,同样的错误页面。 So it seems some configuration incorrect for nuxt.因此,nuxt 似乎有些配置不正确。
I get the same issue when using version 2.12.2.我在使用 2.12.2 版时遇到了同样的问题。 Downgrading to 2.11.0 solved the issue for me.降级到 2.11.0 为我解决了这个问题。
The url for AWS S3 as static hosting need specific index file appended, ie index.html. AWS S3 的 url 作为 static 托管需要附加特定的索引文件,即 index.html。
Router need to be adjusted, Nuxt provides config for settings directly to vue-router, by using 'router: {}'.路由器需要调整,Nuxt 直接向 vue-router 提供 config 设置,使用 'router: {}'。
The following config works for this scenario.以下配置适用于这种情况。
// in nuxt.config.js
mode: 'spa',
router: {
mode: 'hash',
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.