Elastic Beanstalk - 升级后为 nginx 替换 .htaccess [英] Elastic Beanstalk - replace .htaccess for nginx after upgrade
问题描述
我将我的 PHP Elastic Beanstalk 实例从 Amazon Linux 2/3.2.1 升级到 Amazon Linux/2.9.17
I upgraded my PHP Elastic Beanstalk instance from Amazon Linux 2/3.2.1 to Amazon Linux/2.9.17
在以前的版本中,我的包中有一个 .htaccess 文件,以便删除 URL 中的文件扩展名,如下所示:
In the previous version I had a .htaccess file in my bundle in order to remove file extensions in URLs like this:
www.example.com/page.php?var=123
变成 www.example.com/page?var=123
升级后,www.example.com/page.php?var=123
工作正常,但 www.example.com/page?var=123
不行.结果,我的应用中的导航被破坏了.
After the upgrade, www.example.com/page.php?var=123
works fine, but www.example.com/page?var=123
does not work. As a result the navigation in my app is broken.
我从其他堆栈溢出问题中了解到,这次升级在 Elastic Beanstalk 平台上,Apache 被 Nginx 取代,这就是为什么不再考虑 .htaccess 的原因.
I learned from other stack overflow questions that with this upgrade of Elastic Beanstalk platform, Apache was replaced with Nginx which is why the .htaccess is not anymore taken into account.
我对 nginx 的了解为零,所以我尝试在线研究如何将相同的行为应用于 nginx.但是我所做的不起作用.看看下面我做了什么:
I have zero knowledge of nginx, so I tried researching online how to apply the same behavior with nginx. But what I have done is not working. See below what I have done:
我在 .ebextensions\nginx\conf.d\myconf.conf 中创建了一个新的配置文件
I created a new config file in .ebextensions\nginx\conf.d\myconf.conf
文件内容如下:
server {
location / {
try_files $uri $uri.html $uri/ @extensionless-php;
index index.html index.htm index.php;
}
location ~ \.php$ {
try_files $uri =404;
}
location @extensionless-php {
rewrite ^(.*)$ $1.php last;
}
}
我是否只应用了文件中所需的部分配置内容?
Am I only applying part of the config content needed in the file ?
推荐答案
基于评论.
Amazon Linux 2 EB 平台默认使用 nginx.但是,Tomcat、Node.js、PHP 和 Python 可以也支持 Apache.由于此选项不是默认选项,您必须在 .ebextentions
中启用:
Amazon Linux 2 EB platform uses nginx as default. However, Tomcat, Node.js, PHP, and Python do also support Apache. Since this option is not default, you have to enable it in your .ebextentions
:
option_settings:
aws:elasticbeanstalk:environment:proxy:
ProxyServer: apache
这篇关于Elastic Beanstalk - 升级后为 nginx 替换 .htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!