Era*_*ray 2 symfony amazon-elastic-beanstalk
我正在尝试将 Symfony 应用程序部署到 Elastic Beanstalk,但看起来 URL 重写不起作用。
使用在 64 位 Amazon Linux 2 上运行的 PHP 7.4平台,文档根目录为/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;
}
Run Code Online (Sandbox Code Playgroud)
但是服务器找不到domain.com/auth/login(但适用于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: "..."
Run Code Online (Sandbox Code Playgroud)
如果我删除 的注释标记 (#) fastcgi_params,则无法找到它。
我发现了一个有趣的“错误” /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
Run Code Online (Sandbox Code Playgroud)
小智 6
要在 AWS Linux 2 上启用 url 重写,您必须添加以下文件(从根目录)。不需要修改nginx.conf
创建文件:
.platform/nginx/conf.d/elasticbeanstalk/01-rewrite.conf
location / {
try_files $uri /index.php$is_args$args;
}
Run Code Online (Sandbox Code Playgroud)
然后,重新部署您的环境
| 归档时间: |
|
| 查看次数: |
452 次 |
| 最近记录: |