无法修复 404 NOT FOUND 错误,因为我无法查看和访问由 Elastic beanstalk 创建的 ec2 中的文件

Posted

技术标签:

【中文标题】无法修复 404 NOT FOUND 错误,因为我无法查看和访问由 Elastic beanstalk 创建的 ec2 中的文件【英文标题】:Unable to fix 404 NOT FOUND error because I cannot see and access the files in ec2 created by Elastic beanstalk 【发布时间】:2021-07-25 02:04:37 【问题描述】:

我对 AWS Elastic Beanstalk 有点陌生 我使用 AWS Elastic Beanstalk 为 Laravel 项目创建了一个 php 7 部署,该项目可以在我的笔记本电脑上完美运行。然后上传我的 Laravel 项目文件,编辑 .env 文件 现在我收到 404 Not Found 错误 在弹性 beanstalk 控制台上,服务器的运行状况良好,但我仍然收到 404 not found 错误。请帮我解决这个问题 我可以创建一个允许我通过 ssh 访问 ec2 的 IAM 用户或笔文件吗? 如何修复 404 NOT FOUND 错误,因为我无法查看和访问由 Elastic beanstalk 创建的 ec2 中的文件 查看下面服务器的日志

----------------------------------------
/var/log/nginx/error.log
----------------------------------------
2021/05/02 10:37:13 [error] 3601#0: *1 "/var/www/html/public/index.php" is not found (2: No such file or directory), client: 203.159.80.30, server: , request: "GET / HTTP/1.1", host: "18.222.4.168:80"
2021/05/02 10:37:13 [error] 3601#0: *1 testing "/var/www/html/public" existence failed (2: No such file or directory) while logging request, client: 203.159.80.30, server: , request: "GET / HTTP/1.1", host: "18.222.4.168:80"
2021/05/02 10:43:42 [error] 3601#0: *2 "/var/www/html/public/index.php" is not found (2: No such file or directory), client: 129.205.124.143, server: , request: "GET / HTTP/1.1", host: "trikleqtspendapi-env.eba-ghdkmh8i.us-east-2.elasticbeanstalk.com"
2021/05/02 10:43:42 [error] 3601#0: *2 testing "/var/www/html/public" existence failed (2: No such file or directory) while logging request, client: 129.205.124.143, server: , request: "GET / HTTP/1.1", host: "trikleqtspendapi-env.eba-ghdkmh8i.us-east-2.elasticbeanstalk.com"


----------------------------------------
/var/log/eb-engine.log
----------------------------------------
2021/05/02 10:31:29.364543 [INFO] Running command /bin/sh -c systemctl start aws-eb.target
2021/05/02 10:31:29.368812 [INFO] Running command /bin/sh -c systemctl enable healthd.service
2021/05/02 10:31:29.449379 [INFO] Running command /bin/sh -c systemctl show -p PartOf healthd.service
2021/05/02 10:31:29.454445 [INFO] Running command /bin/sh -c systemctl is-active healthd.service
2021/05/02 10:31:29.457846 [INFO] Running command /bin/sh -c systemctl start healthd.service
2021/05/02 10:31:29.482778 [INFO] Copying file /opt/elasticbeanstalk/config/private/healthd/healthd_logformat.conf to /var/proxy/staging/nginx/conf.d/healthd_logformat.conf
2021/05/02 10:31:29.484360 [INFO] Copying file /opt/elasticbeanstalk/config/private/healthd/healthd_nginx.conf to /var/proxy/staging/nginx/conf.d/elasticbeanstalk/healthd.conf
2021/05/02 10:31:29.486171 [INFO] Executing instruction: configure php-fpm
2021/05/02 10:31:29.491762 [INFO] Executing instruction: configure log streaming
2021/05/02 10:31:29.491773 [INFO] log streaming is not enabled
2021/05/02 10:31:29.491776 [INFO] disable log stream
2021/05/02 10:31:29.491789 [INFO] Running command /bin/sh -c systemctl show -p PartOf amazon-cloudwatch-agent.service
2021/05/02 10:31:29.501425 [INFO] Running command /bin/sh -c systemctl stop amazon-cloudwatch-agent.service
2021/05/02 10:31:29.507101 [INFO] Executing instruction: GetToggleForceRotate
2021/05/02 10:31:29.507113 [INFO] Checking if logs need forced rotation
2021/05/02 10:31:29.507131 [INFO] Running command /bin/sh -c /opt/aws/bin/cfn-get-metadata -s arn:aws:cloudformation:us-east-2:630589988206:stack/awseb-e-pw9i7apndy-stack/5104d330-ab31-11eb-815f-0a30b5a1ab58 -r AWSEBAutoScalingGroup --region us-east-2
2021/05/02 10:31:30.087814 [INFO] Running command /bin/sh -c /opt/aws/bin/cfn-get-metadata -s arn:aws:cloudformation:us-east-2:630589988206:stack/awseb-e-pw9i7apndy-stack/5104d330-ab31-11eb-815f-0a30b5a1ab58 -r AWSEBBeanstalkMetadata --region us-east-2
2021/05/02 10:31:30.620774 [INFO] Procfile not found. Generating default rsyslog config
2021/05/02 10:31:30.621989 [INFO] Running command /bin/sh -c systemctl restart rsyslog.service
2021/05/02 10:31:30.639310 [INFO] Executing instruction: PostBuildEbExtension
2021/05/02 10:31:30.639330 [INFO] Starting executing the config set Infra-EmbeddedPostBuild.
2021/05/02 10:31:30.639343 [INFO] Running command /bin/sh -c /opt/aws/bin/cfn-init -s arn:aws:cloudformation:us-east-2:630589988206:stack/awseb-e-pw9i7apndy-stack/5104d330-ab31-11eb-815f-0a30b5a1ab58 -r AWSEBAutoScalingGroup --region us-east-2 --configsets Infra-EmbeddedPostBuild
2021/05/02 10:31:30.957729 [INFO] Finished executing the config set Infra-EmbeddedPostBuild.

2021/05/02 10:31:30.957750 [INFO] Executing instruction: CleanEbExtensions
2021/05/02 10:31:30.957774 [INFO] Cleaned ebextensions subdirectories from app staging directory.
2021/05/02 10:31:30.957778 [INFO] Executing instruction: RunAppDeployPreDeployHooks
2021/05/02 10:31:30.957798 [INFO] The dir .platform/hooks/predeploy/ does not exist in the application. Skipping this step...
2021/05/02 10:31:30.957803 [INFO] Executing instruction: stop X-Ray
2021/05/02 10:31:30.957807 [INFO] stop X-Ray ...
2021/05/02 10:31:30.957821 [INFO] Running command /bin/sh -c systemctl show -p PartOf xray.service
2021/05/02 10:31:30.965110 [WARN] stopProcess Warning: process xray is not registered 
2021/05/02 10:31:30.965139 [INFO] Running command /bin/sh -c systemctl stop xray.service
2021/05/02 10:31:30.972353 [INFO] Executing instruction: stop proxy
2021/05/02 10:31:30.972370 [INFO] Running command /bin/sh -c systemctl show -p PartOf httpd.service
2021/05/02 10:31:30.980459 [WARN] deregisterProcess Warning: process httpd is not registered, skipping...

2021/05/02 10:31:30.980487 [INFO] Running command /bin/sh -c systemctl show -p PartOf nginx.service
2021/05/02 10:31:30.986489 [WARN] deregisterProcess Warning: process nginx is not registered, skipping...

2021/05/02 10:31:30.986501 [INFO] Executing instruction: stop php-fpm
2021/05/02 10:31:30.986522 [INFO] Running command /bin/sh -c systemctl show -p PartOf php-fpm.service
2021/05/02 10:31:30.991331 [WARN] stopProcess Warning: process php-fpm is not registered 
2021/05/02 10:31:30.991360 [INFO] Running command /bin/sh -c systemctl stop php-fpm.service
2021/05/02 10:31:30.995942 [INFO] Executing instruction: FlipApplication
2021/05/02 10:31:30.996531 [INFO] create soft link from /var/app/current/ to /var/www/html
2021/05/02 10:31:30.996560 [INFO] Executing instruction: start X-Ray
2021/05/02 10:31:30.996567 [INFO] X-Ray is not enabled.
2021/05/02 10:31:30.996572 [INFO] Executing instruction: start php-fpm
2021/05/02 10:31:30.996641 [INFO] Running command /bin/sh -c systemctl show -p PartOf php-fpm.service
2021/05/02 10:31:31.002929 [INFO] Running command /bin/sh -c systemctl daemon-reload
2021/05/02 10:31:31.073037 [INFO] Running command /bin/sh -c systemctl reset-failed
2021/05/02 10:31:31.076919 [INFO] Running command /bin/sh -c systemctl show -p PartOf php-fpm.service
2021/05/02 10:31:31.081715 [INFO] Running command /bin/sh -c systemctl is-active php-fpm.service
2021/05/02 10:31:31.085118 [INFO] Running command /bin/sh -c systemctl start php-fpm.service
2021/05/02 10:31:31.349359 [INFO] Executing instruction: start proxy with new configuration
2021/05/02 10:31:31.349393 [INFO] Running command /bin/sh -c /usr/sbin/nginx -t -c /var/proxy/staging/nginx/nginx.conf
2021/05/02 10:31:31.370795 [INFO] Running command /bin/sh -c cp -rp /var/proxy/staging/nginx/* /etc/nginx
2021/05/02 10:31:31.374022 [INFO] Running command /bin/sh -c systemctl show -p PartOf nginx.service
2021/05/02 10:31:31.380855 [INFO] Running command /bin/sh -c systemctl daemon-reload
2021/05/02 10:31:31.457630 [INFO] Running command /bin/sh -c systemctl reset-failed
2021/05/02 10:31:31.461627 [INFO] Running command /bin/sh -c systemctl show -p PartOf nginx.service
2021/05/02 10:31:31.466574 [INFO] Running command /bin/sh -c systemctl is-active nginx.service
2021/05/02 10:31:31.469974 [INFO] Running command /bin/sh -c systemctl start nginx.service
2021/05/02 10:31:31.505744 [INFO] Executing instruction: configureSqsd
2021/05/02 10:31:31.505760 [INFO] This is a web server environment instance, skip configure sqsd daemon ...
2021/05/02 10:31:31.505765 [INFO] Executing instruction: startSqsd
2021/05/02 10:31:31.505769 [INFO] This is a web server environment instance, skip start sqsd daemon ...
2021/05/02 10:31:31.505777 [INFO] Executing instruction: Track pids in healthd
2021/05/02 10:31:31.505782 [INFO] This is an enhanced health env...
2021/05/02 10:31:31.505794 [INFO] Running command /bin/sh -c systemctl show -p ConsistsOf aws-eb.target | cut -d= -f2
2021/05/02 10:31:31.512459 [INFO] php-fpm.service nginx.service healthd.service cfn-hup.service

2021/05/02 10:31:31.512478 [INFO] Running command /bin/sh -c systemctl show -p ConsistsOf eb-app.target | cut -d= -f2
2021/05/02 10:31:31.517149 [INFO] 

2021/05/02 10:31:31.517270 [INFO] Executing instruction: RunAppDeployPostDeployHooks
2021/05/02 10:31:31.517283 [INFO] The dir .platform/hooks/postdeploy/ does not exist in the application. Skipping this step...
2021/05/02 10:31:31.517287 [INFO] Executing cleanup logic
2021/05/02 10:31:31.517408 [INFO] CommandService Response: "status":"SUCCESS","api_version":"1.0","results":["status":"SUCCESS","msg":"Engine execution has succeeded.","returncode":0,"events":["msg":"Instance deployment: You didn't include a 'composer.json' file in your source bundle. The deployment didn't install Composer dependencies.","timestamp":1619951489,"severity":"INFO","msg":"Instance deployment completed successfully.","timestamp":1619951491,"severity":"INFO"]]

2021/05/02 10:31:31.517585 [INFO] Platform Engine finished execution on command: app-deploy

2021/05/02 10:47:20.878327 [INFO] Starting...
2021/05/02 10:47:20.878386 [INFO] Starting EBPlatform-PlatformEngine
2021/05/02 10:47:20.878402 [INFO] reading event message file
2021/05/02 10:47:20.878500 [INFO] no eb envtier info file found, skip loading env tier info.
2021/05/02 10:47:20.878563 [INFO] Engine received EB command cfn-hup-exec

2021/05/02 10:47:20.957130 [INFO] Running command /bin/sh -c /opt/aws/bin/cfn-get-metadata -s arn:aws:cloudformation:us-east-2:630589988206:stack/awseb-e-pw9i7apndy-stack/5104d330-ab31-11eb-815f-0a30b5a1ab58 -r AWSEBAutoScalingGroup --region us-east-2
2021/05/02 10:47:21.259415 [INFO] Running command /bin/sh -c /opt/aws/bin/cfn-get-metadata -s arn:aws:cloudformation:us-east-2:630589988206:stack/awseb-e-pw9i7apndy-stack/5104d330-ab31-11eb-815f-0a30b5a1ab58 -r AWSEBBeanstalkMetadata --region us-east-2
2021/05/02 10:47:21.609138 [INFO] checking whether command tail-log is applicable to this instance...
2021/05/02 10:47:21.609153 [INFO] this command is applicable to the instance, this instance should execute the command
2021/05/02 10:47:21.609157 [INFO] Engine command: (tail-log)

2021/05/02 10:47:21.609207 [INFO] Executing instruction: GetTailLogs
2021/05/02 10:47:21.609212 [INFO] Tail Logs...
2021/05/02 10:47:21.609472 [INFO] Running command /bin/sh -c tail -n 100 /var/log/nginx/access.log
2021/05/02 10:47:21.611205 [INFO] Running command /bin/sh -c tail -n 100 /var/log/nginx/error.log
2021/05/02 10:47:21.612684 [INFO] Running command /bin/sh -c tail -n 100 /var/log/eb-engine.log

【问题讨论】:

我真的很难过,因为世界上没有人能帮我解决这个问题:( 直接访问 Elastic Beanstalk 实例的最简单方法是通过 EB CLI。安装 CLI 并对其进行正确配置后,您可以使用以下命令:eb listeb useeb ssh 查看、配置和访问您的 EB 应用程序和实例。您还可以在包含的屏幕截图的第三个选项卡中直接找到 SSH 的说明。最后,EB 不利用.env 文件。环境变量在 EB Admin online 的 Configuration > Software > Environment properties 部分定义。 【参考方案1】:

我在另一台服务器上重新测试了上传的文件夹,发现文件夹结构存在问题并修复了它,现在很好 感谢您的投入

【讨论】:

以上是关于无法修复 404 NOT FOUND 错误,因为我无法查看和访问由 Elastic beanstalk 创建的 ec2 中的文件的主要内容,如果未能解决你的问题,请参考以下文章

SpringMVCMacBook IDEA2020.2版本如何修复HelloSpringMVC项目运行时页面显示404的问题

网页打不开QQ空间显示HTTP404淘宝网上不了,专家解答。有多加分!

使用router.push的name属性调转时无法匹配404页面

无法使用 asyncio/aiohttp 返回 404 响应

Route 上的 404 页面无法按预期与孩子一起工作

部署webapi 到iis7.5 失败 404.0 求助