红色警报 [AWS]
Posted
技术标签:
【中文标题】红色警报 [AWS]【英文标题】:Red alert [AWS] 【发布时间】:2015-09-28 05:28:08 【问题描述】:简而言之,我希望能够使用 htaccess 来执行各种重写命令。我正在使用 AWS elasticbeanstalk,下面是我尝试让 htaccess 工作时的困境。
我的实例上传失败,收到红色警报,如下图所示:
基本上我已经使用 .ebextensions 覆盖所有内容,以允许 htaccess 使用以下代码:
files:
"/etc/httpd/conf.d/enable_mod_rewrite.conf":
mode: "644"
owner: root
group: root
content: |
AllowOverride All
但这不是导致问题的原因。运行的问题是这样的:
RewriteEngine On
位于 htaccess 中。几乎就像它不能接受 rewritenegine 被打开一样。
更新:
在 /var/log/eb-activity.log 中:
Command CMD-TailLogs succeeded.
[2015-07-10T10:25:09.784Z] INFO [25589] - [CMD-TailLogs] : Starting activity...
[2015-07-10T10:25:10.206Z] INFO [25589] - [CMD-TailLogs/AddonsBefore] : Starting activity...
[2015-07-10T10:25:10.207Z] INFO [25589] - [CMD-TailLogs/AddonsBefore] : Completed activity.
[2015-07-10T10:25:10.207Z] INFO [25589] - [CMD-TailLogs/TailLogs] : Starting activity...
[2015-07-10T10:25:10.207Z] INFO [25589] - [CMD-TailLogs/TailLogs/TailLogs] : Starting activity...
在 /var/log/eb-commandprocessor.log 中
[2015-07-10T10:37:19.644Z] DEBUG [25873] : Checking if the command processor should execute...
[2015-07-10T10:37:19.645Z] DEBUG [25873] : Checking whether the command is applicable to instance (i-80bbbd77)..
[2015-07-10T10:37:19.645Z] INFO [25873] : Command is applicable to this instance (i-80bbbd77)..
[2015-07-10T10:37:19.645Z] DEBUG [25873] : Checking if the received command stage is valid..
[2015-07-10T10:37:19.645Z] INFO [25873] : No stage_num in command. Valid stage..
[2015-07-10T10:37:19.645Z] INFO [25873] : Command processor should execute command.
[2015-07-10T10:37:19.645Z] DEBUG [25873] : Storing current stage..
[2015-07-10T10:37:19.645Z] DEBUG [25873] : Stage_num does not exist. Not saving null stage. Returning..
[2015-07-10T10:37:19.646Z] INFO [25873] : Executing command: CMD-TailLogs...
[2015-07-10T10:37:19.646Z] DEBUG [25873] : Reading config file: /etc/elasticbeanstalk/.aws-eb-stack.properties
[2015-07-10T10:37:19.647Z] DEBUG [25873] : Refreshing metadata..
[2015-07-10T10:37:20.061Z] DEBUG [25873] : Refreshed environment metadata.
[2015-07-10T10:37:20.061Z] DEBUG [25873] : Retrieving metadata for key: AWS::ElasticBeanstalk::Ext||_ContainerConfigFileContent||commands..
[2015-07-10T10:37:20.062Z] DEBUG [25873] : Retrieving metadata for key: AWS::ElasticBeanstalk::Ext||_API||_Commands..
[2015-07-10T10:37:20.064Z] INFO [25873] : Found enabled addons: ["logpublish"].
[2015-07-10T10:37:20.066Z] INFO [25873] : Updating Command definition of addon logpublish.
[2015-07-10T10:37:20.066Z] DEBUG [25873] : Loaded definition of Command CMD-TailLogs.
[2015-07-10T10:37:20.066Z] INFO [25873] : Executing command CMD-TailLogs activities...
[2015-07-10T10:37:20.066Z] DEBUG [25873] : Setting environment variables..
[2015-07-10T10:37:20.066Z] INFO [25873] : Running AddonsBefore for command CMD-TailLogs...
[2015-07-10T10:37:20.067Z] DEBUG [25873] : Running stages of Command CMD-TailLogs from stage 0 to stage 0...
[2015-07-10T10:37:20.067Z] INFO [25873] : Running stage 0 of command CMD-TailLogs...
[2015-07-10T10:37:20.067Z] DEBUG [25873] : Loaded 1 actions for stage 0.
[2015-07-10T10:37:20.067Z] INFO [25873] : Running 1 of 1 actions: TailLogs...
更新3我的 .htaccess 文件的内容
RewriteEngine On
RewriteCond %THE_REQUEST /searchPage.php\?crs_category=([^\s]+) [NC]
RewriteRule ^ category/%1? [NC,R,L]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^category/([^/]+)/?$ searchPage.php?crs_category=$1 [QSA,L,NC]
【问题讨论】:
我建议你登录实例,看看 nginx 日志是怎么说的 【参考方案1】:
AllowOverride
仅在指定的<Directory>
部分中有效 没有正则表达式,不在<Location>
,<DirectoryMatch>
或<Files>
部分。来源:Apache Core Module
您将AllowOverride
放入/etc/httpd/conf.d/enable_mod_rewrite.conf
。这可能会导致 Apache 无法启动。
我刚刚尝试使用默认的 Elastic Beanstalk 示例 PHP 配置(请参阅 Supported Platforms 和 Sample Application)。我还在示例 PHP 应用程序中添加了两个新文件:
phpinfo.php
<?php
phpinfo();
.htaccess
RewriteEngine on
RewriteRule ^/?info.html$ phpinfo.php [L]
结果是:
默认情况下,Elastic Beanstalk PHP 环境已将mod_rewrite
和AllowOverride All
启用到PHP 应用程序目录。
我也尝试添加您的.ebextensions
脚本(添加)。
files: "/etc/httpd/conf.d/enable_mod_rewrite.conf": mode: "644" owner: root group: root content: | AllowOverride All
部署后,Apache服务器无法启动,我无法访问网络。这是由错误的配置引起的。错误是我曾经在我的回答中说过。
解决方案可能是删除您的 enable_mod_rewrite.conf
并使用默认环境。
更新
我尝试使用简单的searchPage.php
和您的.htaccess
,但稍作修改后,您在第二行的^
和category
之间有一个额外的空格。
.htaccess
RewriteEngine On
RewriteCond %THE_REQUEST searchPage.php\?crs_category=([^\s]+) [NC]
RewriteRule ^category/$1? [NC,R,L]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^category/([^/]+)/?$ searchPage.php?crs_category=$1 [QSA,L,NC]
searchPage.php
<?php
header('Content-Type: text/plain');
print_r($_SERVER);
print_r($_REQUEST);
我试着做一个卷曲:
$ curl -v 'http://default-environment-zjqxqumicq.elasticbeanstalk.com/searchPage.php?crs_category=test'
* Hostname was NOT found in DNS cache
* Trying 54.173.237.116...
* Connected to default-environment-zjqxqumicq.elasticbeanstalk.com (54.173.237.116) port 80 (#0)
> GET /searchPage.php?crs_category=test HTTP/1.1
> User-Agent: curl/7.35.0
> Host: default-environment-zjqxqumicq.elasticbeanstalk.com
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: text/plain;charset=UTF-8
< Date: Tue, 21 Jul 2015 13:27:56 GMT
* Server Apache is not blacklisted
< Server: Apache
< Content-Length: 1490
< Connection: keep-alive
<
Array
(
[PHP_MEMORY_LIMIT] => 256M
[PHP_MAX_EXECUTION_TIME] => 60
[PHP_DISPLAY_ERRORS] => Off
[PHP_COMPOSER_OPTIONS] =>
[PHP_ALLOW_URL_FOPEN] => On
[PHP_ZLIB_OUTPUT_COMPRESSION] => Off
[PHP_DOCUMENT_ROOT] => /
[PHP_DATE_TIMEZONE] => UTC
[HTTP_HOST] => default-environment-zjqxqumicq.elasticbeanstalk.com
[HTTP_ACCEPT] => */*
[HTTP_USER_AGENT] => curl/7.35.0
[HTTP_X_FORWARDED_FOR] => 149.129.122.128
[HTTP_X_FORWARDED_PORT] => 80
[HTTP_X_FORWARDED_PROTO] => http
[HTTP_CONNECTION] => keep-alive
[PATH] => /usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
[SERVER_SIGNATURE] =>
[SERVER_SOFTWARE] => Apache
[SERVER_NAME] => default-environment-zjqxqumicq.elasticbeanstalk.com
[SERVER_ADDR] => 172.31.5.238
[SERVER_PORT] => 80
[REMOTE_ADDR] => 172.31.30.235
[DOCUMENT_ROOT] => /var/www/html/
[REQUEST_SCHEME] => http
[CONTEXT_PREFIX] =>
[CONTEXT_DOCUMENT_ROOT] => /var/www/html/
[SERVER_ADMIN] => root@localhost
[SCRIPT_FILENAME] => /var/www/html/searchPage.php
[REMOTE_PORT] => 24890
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] => crs_category=test
[REQUEST_URI] => /searchPage.php?crs_category=test
[SCRIPT_NAME] => /searchPage.php
[PHP_SELF] => /searchPage.php
[REQUEST_TIME_FLOAT] => 1437485276.635
[REQUEST_TIME] => 1437485276
)
Array
(
[crs_category] => test
)
* Connection #0 to host default-environment-zjqxqumicq.elasticbeanstalk.com left intact
和
$ curl -v 'http://default-environment-zjqxqumicq.elasticbeanstalk.com/category/test'
* Hostname was NOT found in DNS cache
* Trying 52.5.119.104...
* Connected to default-environment-zjqxqumicq.elasticbeanstalk.com (52.5.119.104) port 80 (#0)
> GET /category/test HTTP/1.1
> User-Agent: curl/7.35.0
> Host: default-environment-zjqxqumicq.elasticbeanstalk.com
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: text/plain;charset=UTF-8
< Date: Tue, 21 Jul 2015 13:30:13 GMT
* Server Apache is not blacklisted
< Server: Apache
< Content-Length: 1918
< Connection: keep-alive
<
Array
(
[REDIRECT_PHP_MEMORY_LIMIT] => 256M
[REDIRECT_PHP_MAX_EXECUTION_TIME] => 60
[REDIRECT_PHP_DISPLAY_ERRORS] => Off
[REDIRECT_PHP_COMPOSER_OPTIONS] =>
[REDIRECT_PHP_ALLOW_URL_FOPEN] => On
[REDIRECT_PHP_ZLIB_OUTPUT_COMPRESSION] => Off
[REDIRECT_PHP_DOCUMENT_ROOT] => /
[REDIRECT_PHP_DATE_TIMEZONE] => UTC
[REDIRECT_STATUS] => 200
[PHP_MEMORY_LIMIT] => 256M
[PHP_MAX_EXECUTION_TIME] => 60
[PHP_DISPLAY_ERRORS] => Off
[PHP_COMPOSER_OPTIONS] =>
[PHP_ALLOW_URL_FOPEN] => On
[PHP_ZLIB_OUTPUT_COMPRESSION] => Off
[PHP_DOCUMENT_ROOT] => /
[PHP_DATE_TIMEZONE] => UTC
[HTTP_HOST] => default-environment-zjqxqumicq.elasticbeanstalk.com
[HTTP_ACCEPT] => */*
[HTTP_USER_AGENT] => curl/7.35.0
[HTTP_X_FORWARDED_FOR] => 149.129.122.128
[HTTP_X_FORWARDED_PORT] => 80
[HTTP_X_FORWARDED_PROTO] => http
[HTTP_CONNECTION] => keep-alive
[PATH] => /usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
[SERVER_SIGNATURE] =>
[SERVER_SOFTWARE] => Apache
[SERVER_NAME] => default-environment-zjqxqumicq.elasticbeanstalk.com
[SERVER_ADDR] => 172.31.5.238
[SERVER_PORT] => 80
[REMOTE_ADDR] => 172.31.11.66
[DOCUMENT_ROOT] => /var/www/html/
[REQUEST_SCHEME] => http
[CONTEXT_PREFIX] =>
[CONTEXT_DOCUMENT_ROOT] => /var/www/html/
[SERVER_ADMIN] => root@localhost
[SCRIPT_FILENAME] => /var/www/html/searchPage.php
[REMOTE_PORT] => 16148
[REDIRECT_QUERY_STRING] => crs_category=test
[REDIRECT_URL] => /category/test
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] => crs_category=test
[REQUEST_URI] => /category/test
[SCRIPT_NAME] => /searchPage.php
[PHP_SELF] => /searchPage.php
[REQUEST_TIME_FLOAT] => 1437485413.02
[REQUEST_TIME] => 1437485413
)
Array
(
[crs_category] => test
)
* Connection #0 to host default-environment-zjqxqumicq.elasticbeanstalk.com left intact
成功了。
【讨论】:
感谢您的回复,是的,您在使用配置文件部署它后收到的回复正是我得到的(Apache 服务器无法启动,我无法访问网络。)如果 htaccess默认情况下启用,我的问题是它为什么不能工作,因为它在 localhost 中工作正常。我在我的初始帖子下包含了一个更新 3 部分,其中包含 htaccess 代码。 .htaccess 文件位于项目的根目录 我以为你的.htaccess
中有一个额外的空间。检查我上面的更新答案。
您能解释一下您的搜索页面吗?你在里面写的内容只是为了测试目的还是让它工作有必要?
有时候,一个新的环境可以解决我们的问题。因为,我们忘记了在旧环境中改变的一些东西。
phpinfo中有mod_rewrite
吗?只是为了确保,通过 ssh 连接到您的 EB EC2 实例并检查 /etc/httpd/.那里的 Apache 配置正确吗?以上是关于红色警报 [AWS]的主要内容,如果未能解决你的问题,请参考以下文章