Nextjs 应用程序无法加载脚本
我构建了一个在本地完美运行的 Next.js 应用程序。 我将其部署在 AWS 上。
我尝试使用 AWS 上的 ALB 访问它,但在控制台中看到以下错误:
当我在本地运行“yarn run build”然后“yarn run start”时,它工作得很好。
那么为什么会发生这种情况呢?
这是我的 Dockerfile
FROM node:14-alpine
WORKDIR /app
COPY package.json ./
RUN yarn install --immutable --immutable-cache --check-cache
ENV NODE_ENV=production
COPY ./ .
RUN yarn build
CMD ["yarn", "run", "start"]
我的 github 操作:
name: Deploy to AWS Fargate with major version
on:
push:
branches:
- PRODUCTION
env:
AWS_REGION: eu-west-1
ECR_REPOSITORY: landing-page
ECS_SERVICE: landing-page-service
ECS_CLUSTER: landing-page
ECS_TASK_DEFINITION: landing-page
CONTAINER_NAME: landing-page
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition ${{ env.ECS_TASK_DEFINITION }} --query taskDefinition > task-definition.json
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ steps.build-image.outputs.image }}
- name: Deploy Amazon ECS task definition with service
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true
顺便说一句,起初我在 .dockerignore
文件中有 .next
,所以我认为它可能会导致问题,但我删除了它并出现问题保存下来。
我正在 AWS 上使用 ALB 运行 Fargate - 仅此而已。
可能出了什么问题?
但这只是它的“初始”。 CSS、图像、js..未完全加载。
I built a Next.js application which works perfect locally.
I deploy it on AWS.
I try to access it using my ALB on AWS, but I see the following errors in the console:
When I run locally "yarn run build" and then "yarn run start" it works perfect.
So why could it happen?
Here is my Dockerfile
FROM node:14-alpine
WORKDIR /app
COPY package.json ./
RUN yarn install --immutable --immutable-cache --check-cache
ENV NODE_ENV=production
COPY ./ .
RUN yarn build
CMD ["yarn", "run", "start"]
My github action:
name: Deploy to AWS Fargate with major version
on:
push:
branches:
- PRODUCTION
env:
AWS_REGION: eu-west-1
ECR_REPOSITORY: landing-page
ECS_SERVICE: landing-page-service
ECS_CLUSTER: landing-page
ECS_TASK_DEFINITION: landing-page
CONTAINER_NAME: landing-page
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition ${{ env.ECS_TASK_DEFINITION }} --query taskDefinition > task-definition.json
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ steps.build-image.outputs.image }}
- name: Deploy Amazon ECS task definition with service
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true
By the way, at first I had .next
in .dockerignore
file so I thought it may cause issues, but I removed it and issues preserved.
I am running Fargate on AWS with and ALB - that's all.
What may went wrong?
But just the "initial" of it.
CSS, images, js.. are not fully loaded.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过为我的网站创建 SSL 证书并使用负载均衡器更新它来“解决”了这个问题。
对我来说就很满足了。
I "solved" this issue by creating a SSL Certificate for my website and update it with the load balancer.
For me it satisfies.