【发布时间】:2021-05-16 08:19:45
【问题描述】:
我有一个在 Beanstalk 上运行的现有 Laravel API 应用程序。它在 EBS 上的更新一直滞后,所以目前我正在升级这个应用程序的平台和 CI/CD。我还遇到了一个问题,这让我在“但它应该工作”级别上摸不着头脑。
我想要什么
所有包含 https://example.com/index.php/endpoint 的 URL 将被重定向到 https://example.com/endpoint 并显示与 https://example.com/index.php/endpoint 相同的内容(包括 URL 的后缀)
我是如何做到这一点的
由于this wonderful answer by cnst,我的以下配置似乎适用于许多人(包括其他一些在线资源)。
server{
index index.php;
if ($request_uri ~* "^(.*/)index\.php/*(.*)$") {
return 301 $1$2;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
# Remove from everywhere index.php
if ($request_uri ~* "^(.*/)index\.php(/?)(.*)") {
return 301 $1$3;
}
}
if (!-d $request_filename) {
rewrite ^/(.+)/$ /$1 permanent;
}
if ($request_uri ~* "\/\/") {
rewrite ^/(.*) /$1 permanent;
}
}
我将此配置放在位于my_project/.platform/nginx/conf.d/proxy.conf 的文件中,根据AWS' documentation,该文件应与项目一起上传并扩展 nginx 配置。据我所知,它确实可以识别它,因为任何拼写错误都会在eb deploy 之后导致错误。我还可以在服务器上看到它已添加到/etc/nginx/conf.d/proxy.conf。
问题
即使正在部署扩展的 proxy.conf 并且其中的配置似乎已被拾取,应用程序也不会拾取重写并让应用程序 URL 以 index.php 运行而不是重写。
-
https://example.com/index.php/endpoint→ 有效 -
https://example.com/endpoint→ 导致服务器生成 404 - Nginx 日志显示
2021/02/12 14:23:24 [error] 7523#0: *35 open() "/var/www/html/public/api" failed (2: No such file or directory),它告诉我它已经搜索了一个文件并且从未尝试通过index.php运行它。
问题
- 我的配置中缺少什么?
- 或者是我忽略或误解了 EBS 的问题?
-
index.php是不是很生气,因为我想把它的脸藏起来不让公众看到?
【问题讨论】:
标签: laravel amazon-web-services nginx url-rewriting amazon-elastic-beanstalk