Elastic beanstalk 上的 Symfony 应用程序在所有路由中显示 404,除了 "/"



我最近开始使用AWS,我正在尝试将我的Symfony API部署到Elastic Beanstalk。我遵循教程中的步骤,但最终我一次又一次地得到了相同的结果:

默认路由"/"返回预期的结果,但是所有其他端点都返回404 nginx错误。我在其他帖子中看到过类似的问题(见Laravel的帖子(,但由于我从未使用过nginx,我不知道如何基于这些问题来解决我的问题。

感谢您的帮助!

AWS教程提供了一个基本的nginx配置文件,该文件在使用api平台时没有提供symfony应用程序所需的位置定义。解决方案是提供您自己的nginx配置文件,该文件提供的正确位置

#/etc/nginx/conf.d/elasticbeanstalk/php.conf

location / {
# try to serve file directly, fallback to index.php
try_files $uri /index.php$is_args$args;
}

location ~* .(?:ico|css|js|gif|webp|jpe?g|png|svg|woff|woff2|eot|ttf|mp4)$ {
# try to serve file directly, fallback to index.php
try_files $uri /index.php$is_args$args;
access_log off;
expires 1y;
add_header Pragma public;
add_header Cache-Control "public";
}
location ~ ^/index.php(/|$) {
include /etc/nginx/fastcgi_params;
fastcgi_pass php-fpm;
fastcgi_split_path_info ^(.+.php)(/.*)$;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}

AWS弹性豆茎提供了一种使用开发目录中的.platform文件夹更新此文件的机制。

看看Alexander Schranz为symfony应用程序设计的弹性豆茎的这个出色的github示例。它提供了正确的nginx配置,以及大多数symfony应用程序所需的几个有用的部署脚本。

Symfony的生产版本需要一个web包——我使用Apache,请参阅文档

https://symfony.com/doc/current/setup/web_server_configuration.html

基本上,只需将Elastic Beanstalk配置更改为使用Apache而不是Nginx,并在应用程序代码上运行

composer require symfony/apache-pack

然后提交并部署eb,您就可以开始工作了。

相关内容

最新更新