symfony - Deploying Symfony App To Elastic Beanstalk
问题描述
I'm trying to deploy a Symfony application to Elastic Beanstalk but it looks like URL rewriting is not working.
Using platform PHP 7.4 running on 64bit Amazon Linux 2 and the document root is /public.
.platform/nginx/conf.d/nginx.conf
server {
listen 80;
root /var/app/current/public;
index index.php;
location / {
# try to serve file directly, fallback to index.php
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
#fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_pass php-fpm;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
#include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
access_log /var/log/nginx/access.log main;
client_header_timeout 60;
client_body_timeout 60;
keepalive_timeout 60;
gzip off;
gzip_comp_level 4;
# Include the Elastic Beanstalk generated locations
#include conf.d/elasticbeanstalk/*.conf;
}
But server cannot find the path for domain.com/auth/login
(but works for domain.com/index.php/auth/login
----------------------------------------
/var/log/nginx/error.log
----------------------------------------
2020/05/16 17:32:48 [warn] 3709#0: conflicting server name "" on 0.0.0.0:80, ignored
2020/05/16 17:32:48 [warn] 3736#0: conflicting server name "" on 0.0.0.0:80, ignored
2020/05/16 17:32:48 [warn] 3740#0: conflicting server name "" on 0.0.0.0:80, ignored
2020/05/16 17:33:29 [error] 3744#0: *2 open() "/var/www/html/public/auth/login" failed (2: No such file or directory), client: 172.31.42.4, server: , request: "GET /auth/login HTTP/1.1", host: "..."
If I remove the comment mark (#) for fastcgi_params
, it's failing to find it.
I found an interesting 'Error' in /var/log/eb-engine.log
:
2020/05/16 18:21:37.054548 [INFO] Running command /bin/sh -c /usr/sbin/nginx -t -c /var/proxy/staging/nginx/nginx.conf
2020/05/16 18:21:37.064522 [ERROR] nginx: the configuration file /var/proxy/staging/nginx/nginx.conf syntax is ok
nginx: configuration file /var/proxy/staging/nginx/nginx.conf test is successful
解决方案
要在 AWS Linux 2 上启用 url 重写,您必须添加以下文件(从根目录)。你不需要修改 nginx.conf
创建文件:
.platform/nginx/conf.d/elasticbeanstalk/01-rewrite.conf
location / {
try_files $uri /index.php$is_args$args;
}
然后,重新部署您的环境
推荐阅读
- javascript - 一行中的 webpack javascript
- rest - 如何使用 Xamarin.Forms 本地 Web API 和 Emulator for Visual Studio 进行访问?
- javascript - javascript通过另一个对象数组中的属性检查添加或替换对象
- reverse-engineering - 以编程方式将资金存入 Steam 钱包?
- android - 如何强制使用 com.google.android.gms:play-services:15.0.0
- javascript - Javascript - 在普通块内提升
- javascript - 根据当地时间更改背景图像
- swift - swift 4模型类错误:从初始化程序返回而不初始化所有存储的属性
- apache - Apache Config:对 WS 后端的 Websockets 代理 WSS 请求
- python - Django - 运行 manage.py 会为 version.py 产生致命错误:不是 git 存储库