简体   繁体   English

如何在 AWS S3 上托管的 dist 中制作 Nuxt 生成的 static spa 文件

[英]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 上还没有运气。


UPDATE:May 6 2020更新:2020 年 5 月 6 日

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.

相关问题 npm build(nuxt build)不会使用 nuxt spa 模式在放大(aws codebuild)中创建 dist 文件夹 - npm build (nuxt build) does not create dist folder in amplify(aws codebuild) using nuxt spa mode Nuxt 3 如何将缓存控制添加到生成的 static 文件 - Nuxt 3 How to add Cache Control to generated static files 如何使`nuxt generate`生成的html完全静态? - How to make html generated by `nuxt generate` fully static? S3 托管 Static 站点上的授权问题 - Authorization Issues on S3 Hosted Static Site 如何让Django看到Vue.js编译生成的dist/static下的文件? - How to let Django see files under dist/static generated by Vue.js compilation? 为什么我的 nuxt static 站点不提供在 Dist 文件夹中找到的 static html 文件? - Why doesn't my nuxt static site serve the static html files found in the Dist folder? NUXT各个dist文件夹什么时候使用,html/.nuxt/dist/html/dist/_nuxt/html/static html/assets? - NUXT when is each dist folder used, html/.nuxt/dist/ html/dist/_nuxt/ html/static html/assets? Nuxt 在发送到 AWS S3 之前将图像转换为 webp - Nuxt convert image to webp before sending to AWS S3 如何使用Nuxt为s3存储桶加载插件? - How to load plugin for s3 bucket with Nuxt? 配置 NGINX 以将“/”位置重定向到托管在 S3 上的 static 站点 - Configure NGINX to redirect '/' location to static site hosted on S3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM